belongs-to.test.js
1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict';
const chai = require('chai'),
expect = chai.expect,
_ = require('lodash'),
Support = require(__dirname + '/../support'),
current = Support.sequelize;
describe(Support.getTestDialectTeaser('belongsTo'), () => {
it('throws when invalid model is passed', () => {
const User = current.define('User');
expect(() => {
User.belongsTo();
}).to.throw('User.belongsTo called with something that\'s not a subclass of Sequelize.Model');
});
it('should not override custom methods with association mixin', () => {
const methods = {
getTask: 'get',
setTask: 'set',
createTask: 'create'
};
const User = current.define('User');
const Task = current.define('Task');
_.each(methods, (alias, method) => {
User.prototype[method] = function() {
const realMethod = this.constructor.associations.task[alias];
expect(realMethod).to.be.a('function');
return realMethod;
};
});
User.belongsTo(Task, { as: 'task' });
const user = User.build();
_.each(methods, (alias, method) => {
expect(user[method]()).to.be.a('function');
});
});
});