Skip to content

Commit

Permalink
First test
Browse files Browse the repository at this point in the history
  • Loading branch information
bravo-kernel committed Aug 16, 2019
1 parent 86277a6 commit f94c0b1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
7 changes: 6 additions & 1 deletion package.json
Expand Up @@ -52,6 +52,7 @@
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jest": "^22.15.1",
"eslint-plugin-jsdoc": "^15.8.0",
"eslint-plugin-prettier": "^3.0.0",
"eslint-plugin-unicorn": "^8.0.0",
Expand Down Expand Up @@ -96,7 +97,8 @@
"plugin:unicorn/recommended"
],
"env": {
"browser": false
"browser": false,
"jest/globals": true
},
"overrides": [
{
Expand All @@ -115,6 +117,9 @@
]
}
}
],
"plugins": [
"jest"
]
},
"esdoc": {
Expand Down
2 changes: 1 addition & 1 deletion test-the-strategy-pattern.js
Expand Up @@ -49,7 +49,7 @@ console.log('OpenAPI v3:');
console.log(userSchema);

// OpenApi requires more than just the model schema for validation so we insert it into the wrapper
const validationSchema = require('./test/strategies/json-api-v3/schema-validation-wrapper');
const validationSchema = require('./test/strategies/openapi-v3/schema-validation-wrapper');

validationSchema.components.schemas.users = userSchema;
console.log('Validation schema object:');
Expand Down
44 changes: 44 additions & 0 deletions test/strategies/openapi-v3/stragegy.test.js
@@ -0,0 +1,44 @@
const Sequelize = require('sequelize');

const sequelize = new Sequelize({
dialect: 'mysql',
});

const { SchemaManager, OpenApi3Strategy } = require('../../../lib');
const schemaWrapper = require('./schema-validation-wrapper');

describe('OpenAPI v3 strategy', function() {
const manager = new SchemaManager();
const strategy = new OpenApi3Strategy();
const userModel = sequelize.import('../../models/user.js').build();

const schema = manager.generate(userModel, strategy);
schemaWrapper.components.schemas.users = schema;

describe('Properties', function() {
it("has a version 3 'openapi' property", function() {
expect(schemaWrapper).toHaveProperty('openapi');
expect(schemaWrapper.openapi).toMatch(/^3\.\d\.\d/); // 3.n.n
});

it("has a non-empty 'schemas' property", function() {
expect(Object.keys(schemaWrapper.components.schemas).length).toBeGreaterThan(0);
});
});

describe('Validation', function() {
it('passes schema validation against xxx', function() {
expect(schemaWrapper).toHaveProperty('openapi');
expect(schemaWrapper.openapi).toMatch(/^3\.\d\.\d/); // 3.n.n
});
});

// @todo this should be detected by eslint-plugin-jest no-disabled-tests (but is not)
// test('', function() {
// console.log('Does nothing');
// });
});

/*
describe('foo', () => {});
*/

0 comments on commit f94c0b1

Please sign in to comment.