Skip to content

Commit

Permalink
Added some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luisfpg committed Aug 9, 2019
1 parent b77b866 commit 3160d93
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 7 additions & 0 deletions test/all-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@
"allOf": [
{
"type": "object",
"required": [
"numberProp"
],
"properties": {
"stringProp": {
"type": "string",
Expand Down Expand Up @@ -131,6 +134,10 @@
},
{
"type": "object",
"required": [
"refEnumProp",
"refObjectProp"
],
"properties": {
"refEnumProp": {
"$ref": "#/components/schemas/RefEnum",
Expand Down
11 changes: 6 additions & 5 deletions test/all-types.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,22 @@ describe('Generation tests using all-types.json', () => {
expect(decl.properties.length).toBe(18);

// Assert the simple types
function assertProperty(name: string, type: string) {
function assertProperty(name: string, type: string, required = false) {
const prop = decl.properties.find(p => p.name === name);
expect(prop).withContext(`${name} property`).toBeDefined();
if (prop) {
expect(prop.type).toEqual(type);
expect(prop.type).withContext(`${name} type`).toEqual(type);
expect(prop.isOptional).withContext(`${name} required`).toBe(!required);
}
}
assertProperty('stringProp', 'string');
assertProperty('integerProp', 'number');
assertProperty('numberProp', 'number');
assertProperty('numberProp', 'number', true);
assertProperty('booleanProp', 'boolean');
assertProperty('anyProp', 'any');

assertProperty('refEnumProp', 'RefEnum');
assertProperty('refObjectProp', 'RefObject');
assertProperty('refEnumProp', 'RefEnum', true);
assertProperty('refObjectProp', 'RefObject', true);
assertProperty('unionProp', 'Union');
assertProperty('containerProp', 'Container');
assertProperty('arrayOfStringsProp', 'Array<string>');
Expand Down

0 comments on commit 3160d93

Please sign in to comment.