From f94c0b1aa5f7e88650522557475ca8c0e944aca1 Mon Sep 17 00:00:00 2001 From: bravo-kernel Date: Fri, 16 Aug 2019 17:42:19 +0200 Subject: [PATCH] First test --- package.json | 7 ++- test-the-strategy-pattern.js | 2 +- .../schema-validation-wrapper.js | 0 test/strategies/openapi-v3/stragegy.test.js | 44 +++++++++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) rename test/strategies/{json-api-v3 => openapi-v3}/schema-validation-wrapper.js (100%) create mode 100644 test/strategies/openapi-v3/stragegy.test.js diff --git a/package.json b/package.json index a06d644..b478440 100644 --- a/package.json +++ b/package.json @@ -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", @@ -96,7 +97,8 @@ "plugin:unicorn/recommended" ], "env": { - "browser": false + "browser": false, + "jest/globals": true }, "overrides": [ { @@ -115,6 +117,9 @@ ] } } + ], + "plugins": [ + "jest" ] }, "esdoc": { diff --git a/test-the-strategy-pattern.js b/test-the-strategy-pattern.js index ca27399..2812e65 100644 --- a/test-the-strategy-pattern.js +++ b/test-the-strategy-pattern.js @@ -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:'); diff --git a/test/strategies/json-api-v3/schema-validation-wrapper.js b/test/strategies/openapi-v3/schema-validation-wrapper.js similarity index 100% rename from test/strategies/json-api-v3/schema-validation-wrapper.js rename to test/strategies/openapi-v3/schema-validation-wrapper.js diff --git a/test/strategies/openapi-v3/stragegy.test.js b/test/strategies/openapi-v3/stragegy.test.js new file mode 100644 index 0000000..74ed2a2 --- /dev/null +++ b/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', () => {}); +*/