forked from asyncapi/modelina
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: update with master (asyncapi#777)
- Loading branch information
1 parent
81a6e14
commit c1f7fad
Showing
4 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { CommonInputModel, CommonModel, FileHelpers, DartFileGenerator, OutputModel } from '../../../src'; | ||
import * as path from 'path'; | ||
|
||
describe('DartFileGenerator', () => { | ||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
describe('generateToFile()', () => { | ||
const doc = { | ||
$id: 'CustomClass', | ||
type: 'object', | ||
additionalProperties: true, | ||
properties: { | ||
someProp: { type: 'string' }, | ||
someEnum: { | ||
$id: 'CustomEnum', | ||
type: 'string', | ||
enum: ['Texas', 'Alabama', 'California'], | ||
} | ||
} | ||
}; | ||
test('should throw accurate error if file cannot be written', async () => { | ||
const generator = new DartFileGenerator(); | ||
const expectedError = new Error('write error'); | ||
jest.spyOn(FileHelpers, 'writerToFileSystem').mockRejectedValue(expectedError); | ||
jest.spyOn(generator, 'generateCompleteModels').mockResolvedValue([new OutputModel('content', new CommonModel(), '', new CommonInputModel(), [])]); | ||
|
||
await expect(generator.generateToFiles(doc, '/test/', {packageName: 'SomePackage'})).rejects.toEqual(expectedError); | ||
expect(generator.generateCompleteModels).toHaveBeenCalledTimes(1); | ||
expect(FileHelpers.writerToFileSystem).toHaveBeenCalledTimes(1); | ||
}); | ||
test('should try and generate models to files', async () => { | ||
const generator = new DartFileGenerator(); | ||
const outputDir = './test'; | ||
const expectedOutputDirPath = path.resolve(outputDir); | ||
const expectedOutputFilePath = path.resolve(`${outputDir}/test.dart`); | ||
const expectedWriteToFileParameters = [ | ||
'content', | ||
expectedOutputFilePath, | ||
]; | ||
jest.spyOn(FileHelpers, 'writerToFileSystem').mockResolvedValue(undefined); | ||
jest.spyOn(generator, 'generateCompleteModels').mockResolvedValue([new OutputModel('content', new CommonModel(), 'test', new CommonInputModel(), [])]); | ||
|
||
await generator.generateToFiles(doc, expectedOutputDirPath, {packageName: 'SomePackage'}); | ||
expect(generator.generateCompleteModels).toHaveBeenCalledTimes(1); | ||
expect(FileHelpers.writerToFileSystem).toHaveBeenCalledTimes(1); | ||
expect((FileHelpers.writerToFileSystem as jest.Mock).mock.calls[0]).toEqual(expectedWriteToFileParameters); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { JavaGenerator } from '../../../../src/generators'; | ||
import { EnumRenderer } from '../../../../src/generators/java/renderers/EnumRenderer'; | ||
import { CommonInputModel, CommonModel } from '../../../../src/models'; | ||
|
||
describe('EnumRenderer', () => { | ||
let renderer: EnumRenderer; | ||
beforeEach(() => { | ||
renderer = new EnumRenderer(JavaGenerator.defaultOptions, new JavaGenerator(), [], new CommonModel(), new CommonInputModel()); | ||
}); | ||
|
||
describe('normalizeKey()', () => { | ||
test('should correctly format " " to correct key', () => { | ||
const key = renderer.normalizeKey('something something'); | ||
expect(key).toEqual('SOMETHING_SOMETHING'); | ||
}); | ||
test('should correctly format "_" to correct key', () => { | ||
const key = renderer.normalizeKey('something_something'); | ||
expect(key).toEqual('SOMETHING_SOMETHING'); | ||
}); | ||
}); | ||
}); |