Skip to content

Commit

Permalink
test(definitions): tag, server, reference new tests structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Pakisan committed Jul 2, 2024
1 parent 03fde74 commit 2eff358
Show file tree
Hide file tree
Showing 41 changed files with 281 additions and 539 deletions.
3 changes: 0 additions & 3 deletions test/definitions/3.0.0/models/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@ import {describe} from 'vitest';
describe('Models Test Suite', async () => {
await import('./channel');
await import('./operation');
await import('./reference');
await import('./server');
await import('./tag');
});
6 changes: 0 additions & 6 deletions test/definitions/3.0.0/models/reference/index.mjs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,52 +1,77 @@
import path from 'path';
import TestHelper from '@test/test-helper';
import TestHelper from '@test/test-helper.mjs';

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

describe('Reference Object', () => {
it('$ref may be empty', () => TestHelper.objectIsValid(
jsonSchema,
path.resolve(__dirname, './empty.json'),
{
"$ref": ""
},
));

it('$ref cannot be number', () => TestHelper.objectIsNotValid(
jsonSchema,
path.resolve(__dirname, './number.json'),
{
"$ref": 1234
},
['must be string']
));

it('$ref cannot be object', () => TestHelper.objectIsNotValid(
jsonSchema,
path.resolve(__dirname, './object.json'),
{
"$ref": {
"$ref": "#/components/schemas/user"
}
},
['must be string']
));

it('$ref cannot be plain string', () => TestHelper.objectIsNotValid(
jsonSchema,
path.resolve(__dirname, './string.json'),
{
"$ref": "string value"
},
['must match format "uri-reference"']
));

it('$ref cannot be boolean', () => TestHelper.objectIsNotValid(
jsonSchema,
path.resolve(__dirname, './boolean.json'),
{
"$ref": true
},
['must be string']
));

it('$ref cannot be null', () => TestHelper.objectIsNotValid(
jsonSchema,
path.resolve(__dirname, './null.json'),
{
"$ref": null
},
['must be string']
));

it('$ref cannot be array', () => TestHelper.objectIsNotValid(
jsonSchema,
path.resolve(__dirname, './array.json'),
{
"$ref": [
1,
null,
false,
"#/components/schemas/user",
{
"$ref": "#/components/schemas/user"
}
]
},
['must be string']
));

it('$ref is URI', () => TestHelper.objectIsValid(
it('$ref MUST be URI', () => TestHelper.objectIsValid(
jsonSchema,
path.resolve(__dirname, './uri.json'),
{
"$ref": "#/components/schemas/user"
},
));
});

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

49 changes: 49 additions & 0 deletions test/definitions/3.0.0/models/reference/reference.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {
JsonSchemaTestSuite,
JsonSchemaTestSuiteConfig,
JsonSchemaTestSuiteData
} from '@test/definitions/base-schema-test.mjs';
import {describe} from 'vitest';

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

const config = new JsonSchemaTestSuiteConfig(
true,
['must have required property \'$ref\''],
true,
[]
);

const data = new JsonSchemaTestSuiteData(
jsonSchema,
[
{
"$ref": "#/components/schemas/user"
}
],
{
"$ref": "#/components/schemas/user"
},
{},
{
"$ref": "#/components/schemas/user",
"x-number": 0,
"x-string": "",
"x-object": {
"property": {}
}
},
{
"$ref": "#/components/schemas/user",
"x-number": 0,
"x-string": "",
"x-object": {
"property": {}
},
"ext-number": 1
}
);

describe('Reference', () => {
new JsonSchemaTestSuite(data, config).testSuite()
});

This file was deleted.

This file was deleted.

This file was deleted.

49 changes: 0 additions & 49 deletions test/definitions/3.0.0/models/reference/reference/index.mjs

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions test/definitions/3.0.0/models/server/index.mjs

This file was deleted.

75 changes: 75 additions & 0 deletions test/definitions/3.0.0/models/server/server variable.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import {describe} from 'vitest';
import {
JsonSchemaTestSuite,
JsonSchemaTestSuiteConfig,
JsonSchemaTestSuiteData
} from '@test/definitions/base-schema-test.mjs';

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

const config = new JsonSchemaTestSuiteConfig(
false,
[],
true,
[]
);

const data = new JsonSchemaTestSuiteData(
jsonSchema,
[
{
"enum": [
"8883",
"8884"
],
"default": "8883",
"description": "To which port connect",
"examples": [
"8883",
"8884"
]
}
],
{},
{
"enum": [
"8883",
"8884"
],
"default": "8883",
"description": "To which port connect",
"examples": [
"8883",
"8884"
]
},
{
"enum": [
"8883",
"8884"
],
"default": "8883",
"description": "To which port connect",
"examples": [
"8883",
"8884"
],
"x-number": 0,
"x-string": "",
"x-object": {
"property": {}
}
},
{
"x-number": 0,
"x-string": "",
"x-object": {
"property": {}
},
"ext-number": 1
}
);

describe('Server Variable', () => {
new JsonSchemaTestSuite(data, config).testSuite()
});
Loading

0 comments on commit 2eff358

Please sign in to comment.