From 1bd41d58cbfad7870c0b53e9a1a9f79b7b98bec5 Mon Sep 17 00:00:00 2001 From: scott-wyatt Date: Fri, 3 Aug 2018 13:34:01 -0400 Subject: [PATCH] [chore] test model extending --- lib/utils.ts | 2 +- package-lock.json | 2 +- package.json | 2 +- test/fixtures/app.js | 4 +++- test/fixtures/testmodel2.js | 34 +++++++++++++++++++++++++++++++++ test/integrations/spool.test.js | 14 ++++++++++++++ 6 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/testmodel2.js diff --git a/lib/utils.ts b/lib/utils.ts index 0567d86..fc4b58d 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -5,7 +5,7 @@ export const Utils = { return [...objValue, ...srcValue] } }, - mergeConfig: (...values) => { + mergeConfig: (...values): {[key: string]: any} => { const config = {} values.forEach(val => { return mergeWith(config, val, Utils.mergeConfigUtil) diff --git a/package-lock.json b/package-lock.json index daf5617..63d8db6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@fabrix/spool-sequelize", - "version": "1.1.7", + "version": "1.1.8", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 88c91c5..57a2bc0 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fabrix/spool-sequelize", - "version": "1.1.7", + "version": "1.1.8", "description": "Spool - Datastore Spool for Sequelize.js http://sequelizejs.com", "scripts": { "build": "tsc -p ./lib/tsconfig.release.json", diff --git a/test/fixtures/app.js b/test/fixtures/app.js index 2e845e6..3256ea3 100755 --- a/test/fixtures/app.js +++ b/test/fixtures/app.js @@ -3,6 +3,7 @@ const _ = require('lodash') const smokesignals = require('smokesignals') const testModel = require('./testmodel') +const testModel2 = require('./testmodel2') const SequelizeResolver = require('../../dist/index').SequelizeResolver const Model = require('@fabrix/fabrix/dist/common').FabrixModel @@ -195,7 +196,8 @@ const App = { return SequelizeResolver } }, - testModel + testModel, + testModel2 } }, config: { diff --git a/test/fixtures/testmodel2.js b/test/fixtures/testmodel2.js new file mode 100644 index 0000000..5e612c8 --- /dev/null +++ b/test/fixtures/testmodel2.js @@ -0,0 +1,34 @@ +const SequelizeResolver = require('../../dist/index').SequelizeResolver +const Test = require('./testmodel') + +const Utils = require('../../dist/utils').Utils + +const TestResolver = class TestResolver extends SequelizeResolver { + +} + +module.exports = Test2 = class Test2 extends Test { + static config(app, Sequelize) { + return Utils.mergeConfig(Test.config(app, Sequelize), { + options: {} + }) + } + + static schema(app, Sequelize) { + return Utils.mergeConfig(Test.schema(app, Sequelize), { + name2: {type: Sequelize.STRING, allowNull: false} + }) + } + + static get resolver () { + return TestResolver + } + + classLevelMethod() { + return 'foo' + } +} + +Test2.prototype.instanceLevelMethod = function() { + return 'bar' +} diff --git a/test/integrations/spool.test.js b/test/integrations/spool.test.js index ef3d0bb..5210b49 100755 --- a/test/integrations/spool.test.js +++ b/test/integrations/spool.test.js @@ -145,4 +145,18 @@ describe('Spool', () => { const instance = global.app.models.testModel.getTableName() done() }) + + describe('Model Extending', () => { + it('should create an instance of an extended model', (done) => { + const instance = global.app.models.testModel2.create({name: 'test', name2: 'test'}) + .then(i => { + assert.equal(i.name, 'test') + assert.equal(i.name2, 'test') + done() + }) + .catch(err => { + done(err) + }) + }) + }) })