-
-
Notifications
You must be signed in to change notification settings - Fork 172
/
models.test.ts
263 lines (250 loc) · 9.68 KB
/
models.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
/* eslint-disable sonarjs/no-duplicate-string */
/* eslint-disable sonarjs/no-identical-functions */
import path from 'path';
import { test } from '@oclif/test';
const generalOptions = ['generate:models'];
const outputDir = './test/commands/generate/models';
describe('models', () => {
test
.stderr()
.stdout()
.command([...generalOptions, 'typescript', 'http://bit.ly/asyncapi'])
.it('works with remote AsyncAPI files', (ctx, done) => {
expect(ctx.stderr).toEqual('');
expect(ctx.stdout).toMatchSnapshot();
done();
});
test
.stderr()
.stdout()
.command([...generalOptions, 'random', './test/specification.yml', `-o=${ path.resolve(outputDir, './random')}`])
.it('fails when it dont know the language', (ctx, done) => {
expect(ctx.stderr).toEqual('Error: Expected random to be one of: typescript, csharp, golang, java, javascript, dart, python, rust, kotlin\nSee more help with --help\n');
expect(ctx.stdout).toEqual('');
done();
});
test
.stderr()
.stdout()
.command([...generalOptions, 'typescript', './test/specification.yml'])
.it('works when generating in memory', (ctx, done) => {
expect(ctx.stderr).toEqual('');
expect(ctx.stdout).toMatchSnapshot();
done();
});
describe('for TypeScript', () => {
test
.stderr()
.stdout()
.command([...generalOptions, 'typescript', './test/specification.yml', `-o=${ path.resolve(outputDir, './ts')}`])
.it('works when file path is passed', (ctx, done) => {
expect(ctx.stderr).toEqual('');
expect(ctx.stdout).toContain(
'Successfully generated the following models: '
);
done();
});
test
.stderr()
.stdout()
.command([...generalOptions, 'typescript', './test/specification.yml', `-o=${ path.resolve(outputDir, './ts')}`, '--tsJsonBinPack'])
.it('works when tsJsonBinPack is set', (ctx, done) => {
expect(ctx.stderr).toEqual('');
expect(ctx.stdout).toContain(
'Successfully generated the following models: '
);
done();
});
test
.stderr()
.stdout()
.command([...generalOptions, 'typescript', './test/specification.yml', '--tsIncludeComments'])
.it('works when tsIncludeComments is set', (ctx, done) => {
expect(ctx.stderr).toEqual('');
expect(ctx.stdout).toMatchSnapshot();
done();
});
});
describe('for JavaScript', () => {
test
.stderr()
.stdout()
.command([...generalOptions, 'javascript', './test/specification.yml', `-o=${ path.resolve(outputDir, './js')}`])
.it('works when file path is passed', (ctx, done) => {
expect(ctx.stdout).toContain(
'Successfully generated the following models: '
);
expect(ctx.stderr).toEqual('');
done();
});
});
describe('for Python', () => {
test
.stderr()
.stdout()
.command([...generalOptions, 'python', './test/specification.yml', `-o=${ path.resolve(outputDir, './python')}`])
.it('works when file path is passed', (ctx, done) => {
expect(ctx.stdout).toContain(
'Successfully generated the following models: '
);
expect(ctx.stderr).toEqual('');
done();
});
});
describe('for Rust', () => {
test
.stderr()
.stdout()
.command([...generalOptions, 'rust', './test/specification.yml', `-o=${ path.resolve(outputDir, './rust')}`])
.it('works when file path is passed', (ctx, done) => {
expect(ctx.stdout).toContain(
'Successfully generated the following models: '
);
expect(ctx.stderr).toEqual('');
done();
});
});
describe('for C#', () => {
test
.stderr()
.stdout()
.command([...generalOptions, 'csharp', './test/specification.yml', `-o=${path.resolve(outputDir, './csharp')}`, '--namespace=\'asyncapi.models\''])
.it('works when file path is passed', (ctx, done) => {
expect(ctx.stderr).toEqual('');
expect(ctx.stdout).toContain(
'Successfully generated the following models: '
);
done();
});
test
.stderr()
.stdout()
.command([...generalOptions, 'csharp', './test/specification.yml', `-o=${ path.resolve(outputDir, './csharp')}`])
.it('fails when no namespace provided', (ctx, done) => {
expect(ctx.stderr).toEqual('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).toEqual('');
done();
});
test
.stderr()
.stdout()
.command([...generalOptions, 'csharp', './test/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).toEqual('');
expect(ctx.stdout).toContain(
'Successfully generated the following models: '
);
done();
});
test
.stderr()
.stdout()
.command([...generalOptions, 'csharp', './test/specification.yml', `-o=${ path.resolve(outputDir, './csharp')}`, '--namespace=\'asyncapi.models\'', '--csharpArrayType=List'])
.it('works when array type is provided', (ctx, done) => {
expect(ctx.stderr).toEqual('');
expect(ctx.stdout).toContain(
'Successfully generated the following models: '
);
done();
});
});
describe('for Java', () => {
test
.stderr()
.stdout()
.command([...generalOptions, 'java', './test/specification.yml', `-o=${ path.resolve(outputDir, './java')}`, '--packageName', 'test.pkg'])
.it('works when file path is passed', (ctx, done) => {
expect(ctx.stderr).toEqual('');
expect(ctx.stdout).toContain(
'Successfully generated the following models: '
);
done();
});
test
.stderr()
.stdout()
.command([...generalOptions, 'java', './test/specification.yml', `-o=${ path.resolve(outputDir, './java')}`])
.it('fails when no package defined', (ctx, done) => {
expect(ctx.stderr).toEqual('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).toEqual('');
done();
});
});
describe('for Go', () => {
test
.stderr()
.stdout()
.command([...generalOptions, 'golang', './test/specification.yml', `-o=${ path.resolve(outputDir, './go')}`, '--packageName', 'asyncapi.models'])
.it('works when file path is passed', (ctx, done) => {
expect(ctx.stderr).toEqual('');
expect(ctx.stdout).toContain(
'Successfully generated the following models: '
);
done();
});
test
.stderr()
.stdout()
.command([...generalOptions, 'golang', './test/specification.yml', `-o=${ path.resolve(outputDir, './go')}`])
.it('fails when no package defined', (ctx, done) => {
expect(ctx.stderr).toEqual('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).toEqual('');
done();
});
});
describe('for Kotlin', () => {
test
.stderr()
.stdout()
.command([...generalOptions, 'kotlin', './test/specification.yml', `-o=${ path.resolve(outputDir, './kotlin')}`, '--packageName', 'asyncapi.models'])
.it('works when file path is passed', (ctx, done) => {
expect(ctx.stderr).toEqual('');
expect(ctx.stdout).toContain(
'Successfully generated the following models: '
);
done();
});
test
.stderr()
.stdout()
.command([...generalOptions, 'kotlin', './test/specification.yml', `-o=${ path.resolve(outputDir, './kotlin')}`])
.it('fails when no package defined', (ctx, done) => {
expect(ctx.stderr).toEqual('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).toEqual('');
done();
});
});
describe('for Dart', () => {
test
.stderr()
.stdout()
.command([...generalOptions, 'dart', './test/specification.yml', `-o=${ path.resolve(outputDir, './dart')}`, '--packageName', 'asyncapi.models'])
.it('works when file path is passed', (ctx, done) => {
expect(ctx.stderr).toEqual('');
expect(ctx.stdout).toContain(
'Successfully generated the following models: '
);
done();
});
test
.stderr()
.stdout()
.command([...generalOptions, 'dart', './test/specification.yml', `-o=${ path.resolve(outputDir, './dart')}`])
.it('fails when no package defined', (ctx, done) => {
expect(ctx.stderr).toEqual('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).toEqual('');
done();
});
});
describe('with logging diagnostics', () => {
test
.stderr()
.stdout()
.command([...generalOptions, 'typescript', 'http://bit.ly/asyncapi', '--log-diagnostics'])
.it('works with remote AsyncAPI files', (ctx, done) => {
expect(ctx.stderr).toEqual('');
expect(ctx.stdout).toMatch('URL http://bit.ly/asyncapi is valid but has (itself and/or referenced documents) governance issues.');
done();
});
});
});