Skip to content

Commit

Permalink
test(definitions): Info properties test
Browse files Browse the repository at this point in the history
  • Loading branch information
Pakisan committed Jun 13, 2024
1 parent ac4493b commit ade8132
Show file tree
Hide file tree
Showing 8 changed files with 619 additions and 5 deletions.
9 changes: 8 additions & 1 deletion test/definitions/3.0.0/models/info/info/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import path from 'path';

const jsonSchema = require('@definitions/3.0.0/info.json');

describe('Info', () => {
describe('Info', async () => {
await import('./properties/description.mjs');
await import('./properties/termsOfService.mjs');
await import('./properties/contact.mjs');
await import('./properties/license.mjs');
await import('./properties/tags.mjs');
await import('./properties/externalDocs.mjs');

it(TestHelper.exampleIsValidTestName, () => TestHelper.objectIsValid(
jsonSchema,
path.resolve(__dirname, './example.json'),
Expand Down
81 changes: 81 additions & 0 deletions test/definitions/3.0.0/models/info/info/properties/contact.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import {describe, it} from 'vitest';
import TestHelper from '@test/test-helper';
import path from 'path';

const jsonSchema = require('@definitions/3.0.0/info.json');

describe('Info: contact', () => {
it(`${TestHelper.propertyIsNotValidWhenIsTestName} null`, () => TestHelper.objectIsNotValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"contact": null
},
['must be object']
));

it(`${TestHelper.propertyIsValidWhenIsTestName} empty`, () => TestHelper.objectIsValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"contact": {}
},
));

it(`${TestHelper.propertyIsNotValidWhenIsTestName} string`, () => TestHelper.objectIsNotValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"contact": "short description"
},
['must be object']
));

it(`${TestHelper.propertyIsValidWhenIsTestName} object`, () => TestHelper.objectIsValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"contact": {
"name": "AsyncAPI",
"url": "https://www.asyncapi.com",
"email": "[email protected]"
}
},
));

it(`${TestHelper.propertyIsNotValidWhenIsTestName} array`, () => TestHelper.objectIsNotValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"contact": [
null, [], "", {}, false, 123
]
},
['must be object']
));

it(`${TestHelper.propertyIsNotValidWhenIsTestName} number`, () => TestHelper.objectIsNotValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"contact": 123
},
['must be object']
));

it(`${TestHelper.propertyIsNotValidWhenIsTestName} boolean`, () => TestHelper.objectIsNotValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"contact": false
},
['must be object']
));
});
80 changes: 80 additions & 0 deletions test/definitions/3.0.0/models/info/info/properties/description.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import {describe, it} from 'vitest';
import TestHelper from '@test/test-helper';
import path from 'path';

const jsonSchema = require('@definitions/3.0.0/info.json');

describe('Info: description', () => {
it(`${TestHelper.propertyIsNotValidWhenIsTestName} null`, () => TestHelper.objectIsNotValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"description": null
},
['must be string']
));

it(`${TestHelper.propertyIsValidWhenIsTestName} empty`, () => TestHelper.objectIsValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"description": ""
},
));

it(`${TestHelper.propertyIsValidWhenIsTestName} string`, () => TestHelper.objectIsValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"description": "short description"
},
));

it(`${TestHelper.propertyIsNotValidWhenIsTestName} object`, () => TestHelper.objectIsNotValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"description": {
"longVariant": "",
"shortVariant": ""
}
},
['must be string']
));

it(`${TestHelper.propertyIsNotValidWhenIsTestName} array`, () => TestHelper.objectIsNotValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"description": [
null, [], "", {}, false, 123
]
},
['must be string']
));

it(`${TestHelper.propertyIsNotValidWhenIsTestName} number`, () => TestHelper.objectIsNotValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"description": 123
},
['must be string']
));

it(`${TestHelper.propertyIsNotValidWhenIsTestName} boolean`, () => TestHelper.objectIsNotValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"description": false
},
['must be string']
));
});
105 changes: 105 additions & 0 deletions test/definitions/3.0.0/models/info/info/properties/externalDocs.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import {describe, it} from 'vitest';
import TestHelper from '@test/test-helper';
import path from 'path';

const jsonSchema = require('@definitions/3.0.0/info.json');

describe('Info: externalDocs', () => {
it(`${TestHelper.propertyIsNotValidWhenIsTestName} null`, () => TestHelper.objectIsNotValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"externalDocs": null
},
[
'must be object',
'must be object',
'must match exactly one schema in oneOf'
]
));

it(`${TestHelper.propertyIsNotValidWhenIsTestName} empty`, () => TestHelper.objectIsNotValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"externalDocs": {}
},
[
'must have required property \'$ref\'',
'must have required property \'url\'',
'must match exactly one schema in oneOf'
]
));

it(`${TestHelper.propertyIsNotValidWhenIsTestName} string`, () => TestHelper.objectIsNotValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"externalDocs": "short description"
},
[
'must be object',
'must be object',
'must match exactly one schema in oneOf'
]
));

it(`${TestHelper.propertyIsValidWhenIsTestName} object`, () => TestHelper.objectIsValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"externalDocs": {
"description" : "Find more info here",
"url" : "https://example.com"
}
},
));

it(`${TestHelper.propertyIsNotValidWhenIsTestName} array`, () => TestHelper.objectIsNotValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"externalDocs": [
null, [], "", {}, false, 123
]
},
[
'must be object',
'must be object',
'must match exactly one schema in oneOf'
]
));

it(`${TestHelper.propertyIsNotValidWhenIsTestName} number`, () => TestHelper.objectIsNotValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"externalDocs": 123
},
[
'must be object',
'must be object',
'must match exactly one schema in oneOf'
]
));

it(`${TestHelper.propertyIsNotValidWhenIsTestName} boolean`, () => TestHelper.objectIsNotValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"externalDocs": false
},
[
'must be object',
'must be object',
'must match exactly one schema in oneOf'
]
));
});
81 changes: 81 additions & 0 deletions test/definitions/3.0.0/models/info/info/properties/license.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import {describe, it} from 'vitest';
import TestHelper from '@test/test-helper';
import path from 'path';

const jsonSchema = require('@definitions/3.0.0/info.json');

describe('Info: license', () => {
it(`${TestHelper.propertyIsNotValidWhenIsTestName} null`, () => TestHelper.objectIsNotValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"license": null
},
['must be object']
));

it(`${TestHelper.propertyIsNotValidWhenIsTestName} empty`, () => TestHelper.objectIsNotValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"license": {}
},
['must have required property \'name\'']
));

it(`${TestHelper.propertyIsNotValidWhenIsTestName} string`, () => TestHelper.objectIsNotValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"license": "short description"
},
['must be object']
));

it(`${TestHelper.propertyIsValidWhenIsTestName} object`, () => TestHelper.objectIsValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"license": {
"name": "Apache License 2.0",
"url": "http://www.apache.org/licenses/"
}
},
));

it(`${TestHelper.propertyIsNotValidWhenIsTestName} array`, () => TestHelper.objectIsNotValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"license": [
null, [], "", {}, false, 123
]
},
['must be object']
));

it(`${TestHelper.propertyIsNotValidWhenIsTestName} number`, () => TestHelper.objectIsNotValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"license": 123
},
['must be object']
));

it(`${TestHelper.propertyIsNotValidWhenIsTestName} boolean`, () => TestHelper.objectIsNotValid(
jsonSchema,
{
"title": "AsyncApi sample",
"version": "2.0",
"license": false
},
['must be object']
));
});
Loading

0 comments on commit ade8132

Please sign in to comment.