Skip to content

Commit

Permalink
Merge pull request #11 from fabrix-app/v1.1
Browse files Browse the repository at this point in the history
[chore] test model extending
  • Loading branch information
scott-wyatt authored Aug 3, 2018
2 parents b14ddba + 1bd41d5 commit a4ec7c2
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -195,7 +196,8 @@ const App = {
return SequelizeResolver
}
},
testModel
testModel,
testModel2
}
},
config: {
Expand Down
34 changes: 34 additions & 0 deletions test/fixtures/testmodel2.js
Original file line number Diff line number Diff line change
@@ -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'
}
14 changes: 14 additions & 0 deletions test/integrations/spool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
})
})

0 comments on commit a4ec7c2

Please sign in to comment.