sequelize-mock-v5 1.2.3 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +51 -51
- package/sequelize-mock-v5-1.3.4.tgz +0 -0
- package/src/model.js +180 -134
- package/src/operators.js +90 -0
- package/src/sequelize.js +8 -1
- package/test/model-definition.spec.js +73 -0
- package/test/model.spec.js +174 -145
package/src/operators.js
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
|
2
|
+
'use strict';
|
3
|
+
/**
|
4
|
+
* Operator symbols to be used when querying data
|
5
|
+
*
|
6
|
+
* @see {@link Model#where}
|
7
|
+
*
|
8
|
+
* @property eq
|
9
|
+
* @property ne
|
10
|
+
* @property gte
|
11
|
+
* @property gt
|
12
|
+
* @property lte
|
13
|
+
* @property lt
|
14
|
+
* @property not
|
15
|
+
* @property is
|
16
|
+
* @property in
|
17
|
+
* @property notIn
|
18
|
+
* @property like
|
19
|
+
* @property notLike
|
20
|
+
* @property iLike
|
21
|
+
* @property notILike
|
22
|
+
* @property startsWith
|
23
|
+
* @property endsWith
|
24
|
+
* @property substring
|
25
|
+
* @property regexp
|
26
|
+
* @property notRegexp
|
27
|
+
* @property iRegexp
|
28
|
+
* @property notIRegexp
|
29
|
+
* @property between
|
30
|
+
* @property notBetween
|
31
|
+
* @property overlap
|
32
|
+
* @property contains
|
33
|
+
* @property contained
|
34
|
+
* @property adjacent
|
35
|
+
* @property strictLeft
|
36
|
+
* @property strictRight
|
37
|
+
* @property noExtendRight
|
38
|
+
* @property noExtendLeft
|
39
|
+
* @property and
|
40
|
+
* @property or
|
41
|
+
* @property any
|
42
|
+
* @property all
|
43
|
+
* @property values
|
44
|
+
* @property col
|
45
|
+
* @property placeholder
|
46
|
+
* @property join
|
47
|
+
*/
|
48
|
+
const Op = {
|
49
|
+
eq: Symbol.for('eq'),
|
50
|
+
ne: Symbol.for('ne'),
|
51
|
+
gte: Symbol.for('gte'),
|
52
|
+
gt: Symbol.for('gt'),
|
53
|
+
lte: Symbol.for('lte'),
|
54
|
+
lt: Symbol.for('lt'),
|
55
|
+
not: Symbol.for('not'),
|
56
|
+
is: Symbol.for('is'),
|
57
|
+
in: Symbol.for('in'),
|
58
|
+
notIn: Symbol.for('notIn'),
|
59
|
+
like: Symbol.for('like'),
|
60
|
+
notLike: Symbol.for('notLike'),
|
61
|
+
iLike: Symbol.for('iLike'),
|
62
|
+
notILike: Symbol.for('notILike'),
|
63
|
+
startsWith: Symbol.for('startsWith'),
|
64
|
+
endsWith: Symbol.for('endsWith'),
|
65
|
+
substring: Symbol.for('substring'),
|
66
|
+
regexp: Symbol.for('regexp'),
|
67
|
+
notRegexp: Symbol.for('notRegexp'),
|
68
|
+
iRegexp: Symbol.for('iRegexp'),
|
69
|
+
notIRegexp: Symbol.for('notIRegexp'),
|
70
|
+
between: Symbol.for('between'),
|
71
|
+
notBetween: Symbol.for('notBetween'),
|
72
|
+
overlap: Symbol.for('overlap'),
|
73
|
+
contains: Symbol.for('contains'),
|
74
|
+
contained: Symbol.for('contained'),
|
75
|
+
adjacent: Symbol.for('adjacent'),
|
76
|
+
strictLeft: Symbol.for('strictLeft'),
|
77
|
+
strictRight: Symbol.for('strictRight'),
|
78
|
+
noExtendRight: Symbol.for('noExtendRight'),
|
79
|
+
noExtendLeft: Symbol.for('noExtendLeft'),
|
80
|
+
and: Symbol.for('and'),
|
81
|
+
or: Symbol.for('or'),
|
82
|
+
any: Symbol.for('any'),
|
83
|
+
all: Symbol.for('all'),
|
84
|
+
values: Symbol.for('values'),
|
85
|
+
col: Symbol.for('col'),
|
86
|
+
placeholder: Symbol.for('placeholder'),
|
87
|
+
join: Symbol.for('join')
|
88
|
+
};
|
89
|
+
|
90
|
+
module.exports = Op;
|
package/src/sequelize.js
CHANGED
@@ -14,7 +14,8 @@ var path = require('path'),
|
|
14
14
|
Utils = require('./utils'),
|
15
15
|
Errors = require('./errors'),
|
16
16
|
DataTypes = require('./data-types')({}),
|
17
|
-
QueryInterface = require('./queryinterface')
|
17
|
+
QueryInterface = require('./queryinterface'),
|
18
|
+
Op = require('./operators');
|
18
19
|
|
19
20
|
/**
|
20
21
|
* Sequelize Mock Object. This can be initialize much the same way that Sequelize itself
|
@@ -410,4 +411,10 @@ Sequelize.prototype.authenticate = async function() {
|
|
410
411
|
return;
|
411
412
|
};
|
412
413
|
|
414
|
+
/**
|
415
|
+
* Operators symbols to be used for querying data
|
416
|
+
* @see {@link Operators}
|
417
|
+
*/
|
418
|
+
Sequelize.Op = Op;
|
419
|
+
|
413
420
|
module.exports = Sequelize;
|
@@ -0,0 +1,73 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var should = require('should');
|
4
|
+
var Sequelize = require('../src/index.js');
|
5
|
+
|
6
|
+
describe('Model Definition Integration', function () {
|
7
|
+
|
8
|
+
describe('modelDefinition property', function () {
|
9
|
+
it('should be available on models defined with sequelize.define()', function () {
|
10
|
+
var sequelize = new Sequelize();
|
11
|
+
var modelDef = {
|
12
|
+
'name': 'STRING',
|
13
|
+
'email': 'STRING',
|
14
|
+
'age': 'INTEGER',
|
15
|
+
};
|
16
|
+
|
17
|
+
var User = sequelize.define('User', modelDef);
|
18
|
+
|
19
|
+
User.should.have.property('modelDefinition').which.is.an.Object();
|
20
|
+
User.modelDefinition.should.equal(modelDef);
|
21
|
+
User.modelDefinition.should.have.property('name').which.is.exactly('STRING');
|
22
|
+
User.modelDefinition.should.have.property('email').which.is.exactly('STRING');
|
23
|
+
User.modelDefinition.should.have.property('age').which.is.exactly('INTEGER');
|
24
|
+
});
|
25
|
+
|
26
|
+
it('should be accessible through model instances', function () {
|
27
|
+
var sequelize = new Sequelize();
|
28
|
+
var modelDef = {
|
29
|
+
'title': 'STRING',
|
30
|
+
'content': 'TEXT',
|
31
|
+
'published': 'BOOLEAN',
|
32
|
+
};
|
33
|
+
|
34
|
+
var Post = sequelize.define('Post', modelDef);
|
35
|
+
var post = Post.build();
|
36
|
+
|
37
|
+
post.Model.should.have.property('modelDefinition').which.is.an.Object();
|
38
|
+
post.Model.modelDefinition.should.equal(modelDef);
|
39
|
+
post.Model.modelDefinition.should.have.property('title').which.is.exactly('STRING');
|
40
|
+
post.Model.modelDefinition.should.have.property('content').which.is.exactly('TEXT');
|
41
|
+
post.Model.modelDefinition.should.have.property('published').which.is.exactly('BOOLEAN');
|
42
|
+
});
|
43
|
+
|
44
|
+
it('should work with Sequelize DataTypes', function () {
|
45
|
+
var sequelize = new Sequelize();
|
46
|
+
var modelDef = {
|
47
|
+
'name': sequelize.STRING,
|
48
|
+
'age': sequelize.INTEGER,
|
49
|
+
'active': sequelize.BOOLEAN,
|
50
|
+
};
|
51
|
+
|
52
|
+
var User = sequelize.define('User', modelDef);
|
53
|
+
|
54
|
+
User.should.have.property('modelDefinition').which.is.an.Object();
|
55
|
+
User.modelDefinition.should.equal(modelDef);
|
56
|
+
User.modelDefinition.should.have.property('name').which.is.exactly(sequelize.STRING);
|
57
|
+
User.modelDefinition.should.have.property('age').which.is.exactly(sequelize.INTEGER);
|
58
|
+
User.modelDefinition.should.have.property('active').which.is.exactly(sequelize.BOOLEAN);
|
59
|
+
});
|
60
|
+
|
61
|
+
it('should handle empty model definitions', function () {
|
62
|
+
var sequelize = new Sequelize();
|
63
|
+
var modelDef = {};
|
64
|
+
|
65
|
+
var EmptyModel = sequelize.define('EmptyModel', modelDef);
|
66
|
+
|
67
|
+
EmptyModel.should.have.property('modelDefinition').which.is.an.Object();
|
68
|
+
EmptyModel.modelDefinition.should.equal(modelDef);
|
69
|
+
Object.keys(EmptyModel.modelDefinition).should.have.length(0);
|
70
|
+
});
|
71
|
+
});
|
72
|
+
|
73
|
+
});
|