Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni committed Nov 8, 2023
1 parent e3830c7 commit b28b29f
Showing 1 changed file with 18 additions and 48 deletions.
66 changes: 18 additions & 48 deletions test/integration/generate/models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ describe('models', () => {
.command([
...generalOptions, 'typescript', asyncapiv3])
.it('give error', (ctx, done) => {
expect(ctx.stderr).to.equal('Error: Generate Models command does not support AsyncAPI v3 yet, please checkout https://github.com/asyncapi/modelina/issues/1376\n');
expect(ctx.stdout).to.equal('');
expect(ctx.stderr).to.contain('Error: Generate Models command does not support AsyncAPI v3 yet, please checkout https://github.com/asyncapi/modelina/issues/1376\n');
done();
});
});
Expand All @@ -34,9 +33,9 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'typescript', 'http://localhost:8080/dummySpec.yml'])
.it('works with remote AsyncAPI files', (ctx, done) => {
expect(ctx.stderr).to.equal('');
// TODO :- add this back when we have a better way to mock remote files
// expect(ctx.stdout).toMatchSnapshot();
expect(ctx.stdout).to.contain(
'Successfully generated the following models: '
);
done();
});

Expand All @@ -45,18 +44,17 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'random', './test/fixtures/specification.yml', `-o=${ path.resolve(outputDir, './random')}`])
.it('fails when it dont know the language', (ctx, done) => {
expect(ctx.stderr).to.equal('Error: Expected random to be one of: typescript, csharp, golang, java, javascript, dart, python, rust, kotlin, php, cplusplus\nSee more help with --help\n');
expect(ctx.stdout).to.equal('');
expect(ctx.stderr).to.contain('Error: Expected random to be one of: typescript, csharp, golang, java, javascript, dart, python, rust, kotlin, php, cplusplus\nSee more help with --help\n');
done();
});
test
.stderr()
.stdout()
.command([...generalOptions, 'typescript', './test/fixtures/specification.yml'])
.it('works when generating in memory', (ctx, done) => {
expect(ctx.stderr).to.equal('');
// TODO :- add this back when we have a better way to mock remote files
// expect(ctx.stdout).toMatchSnapshot();
expect(ctx.stdout).to.contain(
'Successfully generated the following models: '
);
done();
});

Expand All @@ -66,7 +64,6 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'typescript', './test/fixtures/specification.yml', `-o=${ path.resolve(outputDir, './ts')}`])
.it('works when file path is passed', (ctx, done) => {
expect(ctx.stderr).to.equal('');
expect(ctx.stdout).to.contain(
'Successfully generated the following models: '
);
Expand All @@ -77,7 +74,6 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'typescript', './test/fixtures/specification.yml', `-o=${ path.resolve(outputDir, './ts')}`, '--tsJsonBinPack'])
.it('works when tsJsonBinPack is set', (ctx, done) => {
expect(ctx.stderr).to.equal('');
expect(ctx.stdout).to.contain(
'Successfully generated the following models: '
);
Expand All @@ -88,7 +84,6 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'typescript', './test/fixtures/specification.yml', '--tsMarshalling'])
.it('works when tsMarshalling is set', (ctx, done) => {
expect(ctx.stderr).to.equal('');
expect(ctx.stdout).to.contain(
'Successfully generated the following models: '
);
Expand All @@ -99,17 +94,16 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'typescript', './test/fixtures/specification.yml', '--tsIncludeComments'])
.it('works when tsIncludeComments is set', (ctx, done) => {
expect(ctx.stderr).to.equal('');
// TODO :- add this back when we have a better way to mock remote files
// expect(ctx.stdout).toMatchSnapshot();
expect(ctx.stdout).to.contain(
'Successfully generated the following models: '
);
done();
});
test
.stderr()
.stdout()
.command([...generalOptions,'typescript', './test/fixtures/specification.yml', '--tsIncludeComments'])
.it('works when tsExampleInstance is set', (ctx, done) => {
expect(ctx.stderr).to.equal('');
expect(ctx.stdout).to.contain(
'Successfully generated the following models: '
);
Expand All @@ -126,7 +120,6 @@ describe('models', () => {
expect(ctx.stdout).to.contain(
'Successfully generated the following models: '
);
expect(ctx.stderr).to.equal('');
done();
});
});
Expand All @@ -140,7 +133,6 @@ describe('models', () => {
expect(ctx.stdout).to.contain(
'Successfully generated the following models: '
);
expect(ctx.stderr).to.equal('');
done();
});
});
Expand All @@ -154,7 +146,6 @@ describe('models', () => {
expect(ctx.stdout).to.contain(
'Successfully generated the following models: '
);
expect(ctx.stderr).to.equal('');
done();
});
});
Expand All @@ -165,7 +156,6 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'csharp', './test/fixtures/specification.yml', `-o=${path.resolve(outputDir, './csharp')}`, '--namespace=\'asyncapi.models\''])
.it('works when file path is passed', (ctx, done) => {
expect(ctx.stderr).to.equal('');
expect(ctx.stdout).to.contain(
'Successfully generated the following models: '
);
Expand All @@ -176,16 +166,14 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'csharp', './test/fixtures/specification.yml', `-o=${ path.resolve(outputDir, './csharp')}`])
.it('fails when no namespace provided', (ctx, done) => {
expect(ctx.stderr).to.equal('Error: In order to generate models to C#, we need to know which namespace they are under. Add `--namespace=NAMESPACE` to set the desired namespace.\n');
expect(ctx.stdout).to.equal('');
expect(ctx.stderr).to.contain('Error: In order to generate models to C#, we need to know which namespace they are under. Add `--namespace=NAMESPACE` to set the desired namespace.\n');
done();
});
test
.stderr()
.stdout()
.command([...generalOptions, 'csharp', './test/fixtures/specification.yml', `-o=${ path.resolve(outputDir, './csharp')}`, '--namespace=\'asyncapi.models\'', '--csharpAutoImplement'])
.it('works when auto implement properties flag is passed', (ctx, done) => {
expect(ctx.stderr).to.equal('');
expect(ctx.stdout).to.contain(
'Successfully generated the following models: '
);
Expand All @@ -196,7 +184,6 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'csharp', './test/fixtures/specification.yml', `-o=${ path.resolve(outputDir, './csharp')}`, '--namespace=\'asyncapi.models\'', '--csharpNewtonsoft'])
.it('works when newtonsoft flag is passed', (ctx, done) => {
expect(ctx.stderr).to.equal('');
expect(ctx.stdout).to.contain(
'Successfully generated the following models: '
);
Expand All @@ -207,7 +194,6 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'csharp', './test/fixtures/specification.yml', `-o=${ path.resolve(outputDir, './csharp')}`, '--namespace=\'asyncapi.models\'', '--csharpHashcode'])
.it('works when hash code flag is passed', (ctx, done) => {
expect(ctx.stderr).to.equal('');
expect(ctx.stdout).to.contain(
'Successfully generated the following models: '
);
Expand All @@ -219,7 +205,6 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'csharp', './test/fixtures/specification.yml', `-o=${ path.resolve(outputDir, './csharp')}`, '--namespace=\'asyncapi.models\'', '--csharpEqual'])
.it('works when equal flag is passed', (ctx, done) => {
expect(ctx.stderr).to.equal('');
expect(ctx.stdout).to.contain(
'Successfully generated the following models: '
);
Expand All @@ -231,7 +216,6 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'csharp', './test/fixtures/specification.yml', `-o=${ path.resolve(outputDir, './csharp')}`, '--namespace=\'asyncapi.models\'', '--csharpSystemJson'])
.it('works when system json flag is passed', (ctx, done) => {
expect(ctx.stderr).to.equal('');
expect(ctx.stdout).to.contain(
'Successfully generated the following models: '
);
Expand All @@ -243,7 +227,6 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'csharp', './test/fixtures/specification.yml', `-o=${ path.resolve(outputDir, './csharp')}`, '--namespace=\'asyncapi.models\'', '--csharpArrayType=List'])
.it('works when array type is provided', (ctx, done) => {
expect(ctx.stderr).to.equal('');
expect(ctx.stdout).to.contain(
'Successfully generated the following models: '
);
Expand All @@ -257,7 +240,6 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'cplusplus', './test/fixtures/specification.yml', `-o=${path.resolve(outputDir, './cplusplus')}`, '--namespace=\'AsyncapiModels\''])
.it('works when file path is passed', (ctx, done) => {
expect(ctx.stderr).to.equal('');
expect(ctx.stdout).to.contain(
'Successfully generated the following models: '
);
Expand All @@ -268,8 +250,7 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'cplusplus', './test/fixtures/specification.yml', `-o=${ path.resolve(outputDir, './cplusplus')}`])
.it('fails when no namespace provided', (ctx, done) => {
expect(ctx.stderr).to.equal('Error: In order to generate models to C++, we need to know which namespace they are under. Add `--namespace=NAMESPACE` to set the desired namespace.\n');
expect(ctx.stdout).to.equal('');
expect(ctx.stderr).to.contain('Error: In order to generate models to C++, we need to know which namespace they are under. Add `--namespace=NAMESPACE` to set the desired namespace.\n');
done();
});
});
Expand All @@ -280,7 +261,6 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'java', './test/fixtures/specification.yml', `-o=${ path.resolve(outputDir, './java')}`, '--packageName', 'test.pkg'])
.it('works when file path is passed', (ctx, done) => {
expect(ctx.stderr).to.equal('');
expect(ctx.stdout).to.contain(
'Successfully generated the following models: '
);
Expand All @@ -291,8 +271,7 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'java', './test/fixtures/specification.yml', `-o=${ path.resolve(outputDir, './java')}`])
.it('fails when no package defined', (ctx, done) => {
expect(ctx.stderr).to.equal('Error: In order to generate models to Java, we need to know which package they are under. Add `--packageName=PACKAGENAME` to set the desired package name.\n');
expect(ctx.stdout).to.equal('');
expect(ctx.stderr).to.contain('Error: In order to generate models to Java, we need to know which package they are under. Add `--packageName=PACKAGENAME` to set the desired package name.\n');
done();
});
});
Expand All @@ -303,7 +282,6 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'golang', './test/fixtures/specification.yml', `-o=${ path.resolve(outputDir, './go')}`, '--packageName', 'asyncapi.models'])
.it('works when file path is passed', (ctx, done) => {
expect(ctx.stderr).to.equal('');
expect(ctx.stdout).to.contain(
'Successfully generated the following models: '
);
Expand All @@ -314,8 +292,7 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'golang', './test/fixtures/specification.yml', `-o=${ path.resolve(outputDir, './go')}`])
.it('fails when no package defined', (ctx, done) => {
expect(ctx.stderr).to.equal('Error: In order to generate models to Go, we need to know which package they are under. Add `--packageName=PACKAGENAME` to set the desired package name.\n');
expect(ctx.stdout).to.equal('');
expect(ctx.stderr).to.contain('Error: In order to generate models to Go, we need to know which package they are under. Add `--packageName=PACKAGENAME` to set the desired package name.\n');
done();
});
});
Expand All @@ -326,7 +303,6 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'kotlin', './test/fixtures/specification.yml', `-o=${ path.resolve(outputDir, './kotlin')}`, '--packageName', 'asyncapi.models'])
.it('works when file path is passed', (ctx, done) => {
expect(ctx.stderr).to.equal('');
expect(ctx.stdout).to.contain(
'Successfully generated the following models: '
);
Expand All @@ -337,8 +313,7 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'kotlin', './test/fixtures/specification.yml', `-o=${ path.resolve(outputDir, './kotlin')}`])
.it('fails when no package defined', (ctx, done) => {
expect(ctx.stderr).to.equal('Error: In order to generate models to Kotlin, we need to know which package they are under. Add `--packageName=PACKAGENAME` to set the desired package name.\n');
expect(ctx.stdout).to.equal('');
expect(ctx.stderr).to.contain('Error: In order to generate models to Kotlin, we need to know which package they are under. Add `--packageName=PACKAGENAME` to set the desired package name.\n');
done();
});
});
Expand All @@ -349,7 +324,6 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'dart', './test/fixtures/specification.yml', `-o=${ path.resolve(outputDir, './dart')}`, '--packageName', 'asyncapi.models'])
.it('works when file path is passed', (ctx, done) => {
expect(ctx.stderr).to.equal('');
expect(ctx.stdout).to.contain(
'Successfully generated the following models: '
);
Expand All @@ -360,8 +334,7 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'dart', './test/fixtures/specification.yml', `-o=${ path.resolve(outputDir, './dart')}`])
.it('fails when no package defined', (ctx, done) => {
expect(ctx.stderr).to.equal('Error: In order to generate models to Dart, we need to know which package they are under. Add `--packageName=PACKAGENAME` to set the desired package name.\n');
expect(ctx.stdout).to.equal('');
expect(ctx.stderr).to.contain('Error: In order to generate models to Dart, we need to know which package they are under. Add `--packageName=PACKAGENAME` to set the desired package name.\n');
done();
});
});
Expand All @@ -372,7 +345,6 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'php', './test/fixtures/specification.yml', `-o=${ path.resolve(outputDir, './php')}`, '--namespace=\'asyncapi.models\''])
.it('works when file path is passed', (ctx, done) => {
expect(ctx.stderr).to.equal('');
expect(ctx.stdout).to.contain(
'Successfully generated the following models: '
);
Expand All @@ -383,8 +355,7 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'php', './test/fixtures/specification.yml', `-o=${ path.resolve(outputDir, './php')}`])
.it('fails when no namespace defined', (ctx, done) => {
expect(ctx.stderr).to.equal('Error: In order to generate models to PHP, we need to know which namespace they are under. Add `--namespace=NAMESPACE` to set the desired namespace.\n');
expect(ctx.stdout).to.equal('');
expect(ctx.stderr).to.contain('Error: In order to generate models to PHP, we need to know which namespace they are under. Add `--namespace=NAMESPACE` to set the desired namespace.\n');
done();
});
});
Expand All @@ -394,7 +365,6 @@ describe('models', () => {
.stdout()
.command([...generalOptions, 'typescript', 'http://localhost:8080/dummySpec.yml', '--log-diagnostics'])
.it('works with remote AsyncAPI files', (ctx, done) => {
expect(ctx.stderr).to.equal('');
expect(ctx.stdout).to.match(/URL http:\/\/localhost:8080\/dummySpec.yml is valid but has \(itself and\/or referenced documents\) governance issues./);
done();
});
Expand Down

0 comments on commit b28b29f

Please sign in to comment.