Skip to content

Commit

Permalink
fix: export new schema and refactor tests for future (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
derberg authored Jun 24, 2021
1 parent a5b72e9 commit fdf6a37
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 69 deletions.
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}.`);
});
});
});

0 comments on commit fdf6a37

Please sign in to comment.