Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: export new schema and refactor tests for future #72

Merged
merged 2 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ module.exports = {
'2.0.0-rc1': require('./schemas/2.0.0-rc1.json'),
'2.0.0-rc2': require('./schemas/2.0.0-rc2.json'),
'2.0.0': require('./schemas/2.0.0.json'),
'2.1.0': require('./schemas/2.1.0.json'),
};
81 changes: 12 additions & 69 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,23 @@
const assert = require('assert');
const fs = require('fs');
const path = require('path');

describe('AsyncAPI', () => {
it('should return an object', () => {
const asyncapi = require('..');
assert(typeof asyncapi === 'object', 'Returned value is not an object.');
});

// Version 2.0.0
it('should check if json schema is exported and if it matches the original file', () => {
fs.readdirSync('schemas').forEach(file => {
fileName = path.parse(file).name;

const asyncapi = require('..');
assert(typeof asyncapi[fileName] === 'object', `Returned object does not contain ${fileName}.`);

it('should return an object with 2.0.0 key', () => {
const asyncapi = require('..');
assert(typeof asyncapi['2.0.0'] === 'object', 'Returned object does not contain 2.0.0.');
});
it('should return schema version 2.0.0', () => {
const asyncapi = require('..')['2.0.0'];
const asyncapi200rc1 = require('../schemas/2.0.0.json');
assert.deepStrictEqual(asyncapi, asyncapi200rc1, 'Returned object is not schema version 2.0.0.');
});

// Version 2.0.0-rc2

it('should return an object with 2.0.0-rc2 key', () => {
const asyncapi = require('..');
assert(typeof asyncapi['2.0.0-rc2'] === 'object', 'Returned object does not contain 2.0.0-rc2.');
});
it('should return schema version 2.0.0-rc2', () => {
const asyncapi = require('..')['2.0.0-rc2'];
const asyncapi200rc1 = require('../schemas/2.0.0-rc2.json');
assert.deepStrictEqual(asyncapi, asyncapi200rc1, 'Returned object is not schema version 2.0.0-rc2.');
});

// Version 2.0.0-rc1

it('should return an object with 2.0.0-rc1 key', () => {
const asyncapi = require('..');
assert(typeof asyncapi['2.0.0-rc1'] === 'object', 'Returned object does not contain 2.0.0-rc1.');
});
it('should return schema version 2.0.0-rc1', () => {
const asyncapi = require('..')['2.0.0-rc1'];
const asyncapi200rc1 = require('../schemas/2.0.0-rc1.json');
assert.deepStrictEqual(asyncapi, asyncapi200rc1, 'Returned object is not schema version 2.0.0-rc1.');
});

// Version 1.2.0

it('should return an object with 1.2.0 key', () => {
const asyncapi = require('..');
assert(typeof asyncapi['1.2.0'] === 'object', 'Returned object does not contain 1.2.0.');
});
it('should return schema version 1.2.0', () => {
const asyncapi = require('..')['1.2.0'];
const asyncapi120 = require('../schemas/1.2.0.json');
assert.deepStrictEqual(asyncapi, asyncapi120, 'Returned object is not schema version 1.2.0.');
});

// Version 1.1.0

it('should return an object with 1.1.0 key', () => {
const asyncapi = require('..');
assert(typeof asyncapi['1.1.0'] === 'object', 'Returned object does not contain 1.1.0.');
});
it('should return schema version 1.1.0', () => {
const asyncapi = require('..')['1.1.0'];
const asyncapi110 = require('../schemas/1.1.0.json');
assert.deepStrictEqual(asyncapi, asyncapi110, 'Returned object is not schema version 1.1.0.');
});

// Version 1.0.0

it('should return an object with 1.0.0 key', () => {
const asyncapi = require('..');
assert(typeof asyncapi['1.0.0'] === 'object', 'Returned object does not contain 1.0.0.');
});
it('should return schema version 1.0.0', () => {
const asyncapi = require('..')['1.0.0'];
const asyncapi100 = require('../schemas/1.0.0.json');
assert.deepStrictEqual(asyncapi, asyncapi100, 'Returned object is not schema version 1.0.0.');
const asyncapiVersion = require('..')[fileName];
const asyncapiSchema = require(`../schemas/${fileName}.json`);
assert.deepStrictEqual(asyncapiVersion, asyncapiSchema, `Returned object is not schema version ${fileName}.`);
});
});
});