diff --git a/test/generators/csharp/CSharpFileGenerator.spec.ts b/test/generators/csharp/CSharpFileGenerator.spec.ts deleted file mode 100644 index 181f3cb300..0000000000 --- a/test/generators/csharp/CSharpFileGenerator.spec.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { CommonInputModel, CommonModel, FileHelpers, CSharpFileGenerator, OutputModel } from '../../../src'; -import * as path from 'path'; - -describe('CSharpFileGenerator', () => { - 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 CSharpFileGenerator(); - 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/', {namespace: 'SomeNamespace'})).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 CSharpFileGenerator(); - const outputDir = './test'; - const expectedOutputDirPath = path.resolve(outputDir); - const expectedOutputFilePath = path.resolve(`${outputDir}/Test.cs`); - 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, {namespace: 'SomeNamespace'}); - expect(generator.generateCompleteModels).toHaveBeenCalledTimes(1); - expect(FileHelpers.writerToFileSystem).toHaveBeenCalledTimes(1); - expect((FileHelpers.writerToFileSystem as jest.Mock).mock.calls[0]).toEqual(expectedWriteToFileParameters); - }); - }); -}); diff --git a/test/generators/dart/DartFileGenerator.spec.ts b/test/generators/dart/DartFileGenerator.spec.ts deleted file mode 100644 index 5577f7678d..0000000000 --- a/test/generators/dart/DartFileGenerator.spec.ts +++ /dev/null @@ -1,51 +0,0 @@ -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); - }); - }); -}); diff --git a/test/generators/go/GoFileGenerator.spec.ts b/test/generators/go/GoFileGenerator.spec.ts deleted file mode 100644 index 396e55b17d..0000000000 --- a/test/generators/go/GoFileGenerator.spec.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { CommonInputModel, CommonModel, FileHelpers, GoFileGenerator, OutputModel } from '../../../src'; -import * as path from 'path'; - -describe('GoFileGenerator', () => { - 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 GoFileGenerator(); - 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: 'some_package'})).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 GoFileGenerator(); - const outputDir = './test'; - const expectedOutputDirPath = path.resolve(outputDir); - const expectedOutputFilePath = path.resolve(`${outputDir}/Test.go`); - 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: 'some_package'}); - expect(generator.generateCompleteModels).toHaveBeenCalledTimes(1); - expect(FileHelpers.writerToFileSystem).toHaveBeenCalledTimes(1); - expect((FileHelpers.writerToFileSystem as jest.Mock).mock.calls[0]).toEqual(expectedWriteToFileParameters); - }); - }); -}); diff --git a/test/generators/javascript/JavaScriptFileGenerator.spec.ts b/test/generators/javascript/JavaScriptFileGenerator.spec.ts deleted file mode 100644 index 074201be9e..0000000000 --- a/test/generators/javascript/JavaScriptFileGenerator.spec.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { CommonInputModel, CommonModel, FileHelpers, JavaScriptFileGenerator, OutputModel } from '../../../src'; -import * as path from 'path'; - -describe('JavaScriptFileGenerator', () => { - 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 JavaScriptFileGenerator(); - const expectedError = new Error('write error'); - jest.spyOn(FileHelpers, 'writerToFileSystem').mockRejectedValue(expectedError); - jest.spyOn(generator, 'generateCompleteModels').mockResolvedValue([new OutputModel('content', new CommonModel(), 'Test', new CommonInputModel(), [])]); - - await expect(generator.generateToFiles(doc, '/test/')).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 JavaScriptFileGenerator(); - const outputDir = './test'; - const expectedOutputDirPath = path.resolve(outputDir); - const expectedOutputFilePath = path.resolve(`${outputDir}/Test.js`); - 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); - expect(generator.generateCompleteModels).toHaveBeenCalledTimes(1); - expect(FileHelpers.writerToFileSystem).toHaveBeenCalledTimes(1); - expect((FileHelpers.writerToFileSystem as jest.Mock).mock.calls[0]).toEqual(expectedWriteToFileParameters); - }); - test('should ignore models that have not been rendered', async () => { - const generator = new JavaScriptFileGenerator(); - const outputDir = './test'; - const expectedOutputDirPath = path.resolve(outputDir); - jest.spyOn(FileHelpers, 'writerToFileSystem').mockResolvedValue(undefined); - jest.spyOn(generator, 'generateCompleteModels').mockResolvedValue([new OutputModel('content', new CommonModel(), '', new CommonInputModel(), [])]); - - const models = await generator.generateToFiles(doc, expectedOutputDirPath); - expect(generator.generateCompleteModels).toHaveBeenCalledTimes(1); - expect(FileHelpers.writerToFileSystem).toHaveBeenCalledTimes(0); - expect(models).toHaveLength(0); - }); - }); -}); diff --git a/test/generators/typescript/TypeScriptFileGenerator.spec.ts b/test/generators/typescript/TypeScriptFileGenerator.spec.ts deleted file mode 100644 index cad65e642b..0000000000 --- a/test/generators/typescript/TypeScriptFileGenerator.spec.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { CommonInputModel, CommonModel, FileHelpers, TypeScriptFileGenerator, OutputModel } from '../../../src'; -import * as path from 'path'; - -describe('TypeScriptFileGenerator', () => { - 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 TypeScriptFileGenerator(); - const expectedError = new Error('write error'); - jest.spyOn(FileHelpers, 'writerToFileSystem').mockRejectedValue(expectedError); - jest.spyOn(generator, 'generateCompleteModels').mockResolvedValue([new OutputModel('content', new CommonModel(), 'Test', new CommonInputModel(), [])]); - - await expect(generator.generateToFiles(doc, '/test/')).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 TypeScriptFileGenerator(); - const outputDir = './test'; - const expectedOutputDirPath = path.resolve(outputDir); - const expectedOutputFilePath = path.resolve(`${outputDir}/Test.ts`); - 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); - expect(generator.generateCompleteModels).toHaveBeenCalledTimes(1); - expect(FileHelpers.writerToFileSystem).toHaveBeenCalledTimes(1); - expect((FileHelpers.writerToFileSystem as jest.Mock).mock.calls[0]).toEqual(expectedWriteToFileParameters); - }); - - test('should ignore models that have not been rendered', async () => { - const generator = new TypeScriptFileGenerator(); - const outputDir = './test'; - const expectedOutputDirPath = path.resolve(outputDir); - jest.spyOn(FileHelpers, 'writerToFileSystem').mockResolvedValue(undefined); - jest.spyOn(generator, 'generateCompleteModels').mockResolvedValue([new OutputModel('content', new CommonModel(), '', new CommonInputModel(), [])]); - - const models = await generator.generateToFiles(doc, expectedOutputDirPath); - expect(generator.generateCompleteModels).toHaveBeenCalledTimes(1); - expect(FileHelpers.writerToFileSystem).toHaveBeenCalledTimes(0); - expect(models).toHaveLength(0); - }); - }); -});