Skip to content

Commit

Permalink
test(definitions): tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Pakisan committed May 23, 2024
1 parent b36845e commit c9f9810
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/definitions/3.0.0/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ describe('Models', () => {
require('./channel');
require('./operation');
require('./server');
require('./tag/tag.js');
require('./reference/reference.js');
require('./reference object/reference-object.js');
});
1 change: 1 addition & 0 deletions test/definitions/3.0.0/models/tag/empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
13 changes: 13 additions & 0 deletions test/definitions/3.0.0/models/tag/extended.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "user",
"description": "User-related messages",
"externalDocs": {
"description" : "Find more info here",
"url" : "https://example.com"
},
"x-number": 0,
"x-string": "",
"x-object": {
"property": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "user"
}
66 changes: 66 additions & 0 deletions test/definitions/3.0.0/models/tag/tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const Ajv = require('ajv');
const assert = require('assert');
const addFormats = require('ajv-formats');
const fs = require('fs');

const ajv = new Ajv({
jsonPointers: true,
allErrors: true,
schemaId: '$id',
logger: false,
validateFormats: true,
strict: false,
});
addFormats(ajv);

const infoJsonSchema = require('../../../../../definitions/3.0.0/tag.json');
const validator = ajv
.addMetaSchema(require('../../../../../definitions/3.0.0/schema.json'))
.addSchema(require('../../../../../definitions/3.0.0/Reference.json'))
.addSchema(require('../../../../../definitions/3.0.0/ReferenceObject.json'))
.addSchema(require('../../../../../definitions/3.0.0/externalDocs.json'))
.addSchema(require('../../../../../definitions/3.0.0/specificationExtension.json'))
.compile(infoJsonSchema);

describe('Reference', () => {
it('empty', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8'));
const validationResult = validator(info);

assert(validationResult === false, 'Reference with empty body is not valid');
assert(validator.errors[0].message === 'must have required property \'name\'');
assert(validator.errors.length === 1);
});

it('without required properties', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/without required properties.json`, 'utf-8'));
const validationResult = validator(info);

assert(validationResult === false, 'Reference without required properties is not valid');
assert(validator.errors[0].message === 'must have required property \'name\'');
assert(validator.errors.length === 1);
});

it('only required properties', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/only required properties.json`, 'utf-8'));
const validationResult = validator(info);

assert(validationResult === true, 'Reference is valid with only required properties');
});

it.skip('extended. Reason: schema doesn\'t check for extensions', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/extended.json`, 'utf-8'));
const validationResult = validator(info);

// TODO: Is it ok?
assert(validationResult === true, 'Reference extensions will not be checked');
});

it.skip('wrongly extended. Reason: schema doesn\'t check for extensions', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/wrongly extended.json`, 'utf-8'));
const validationResult = validator(info);

// TODO: Is it ok?
assert(validationResult === true, 'Reference extensions will not be checked');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"description": "User-related messages",
"externalDocs": {
"description" : "Find more info here",
"url" : "https://example.com"
}
}
14 changes: 14 additions & 0 deletions test/definitions/3.0.0/models/tag/wrongly extended.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "user",
"description": "User-related messages",
"externalDocs": {
"description" : "Find more info here",
"url" : "https://example.com"
},
"x-number": 0,
"x-string": "",
"x-object": {
"property": {}
},
"ext-number": 1
}

0 comments on commit c9f9810

Please sign in to comment.