dao.test.js
4.13 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
'use strict';
const chai = require('chai'),
expect = chai.expect,
Support = require('../../support'),
dialect = Support.getTestDialect(),
DataTypes = require('../../../../lib/data-types');
if (dialect !== 'mariadb') return;
describe('[MariaDB Specific] DAO', () => {
beforeEach(function() {
this.sequelize.options.quoteIdentifiers = true;
this.User = this.sequelize.define('User', {
username: DataTypes.STRING,
email: DataTypes.STRING,
location: DataTypes.GEOMETRY()
});
return this.User.sync({ force: true });
});
afterEach(function() {
this.sequelize.options.quoteIdentifiers = true;
});
describe('integers', () => {
describe('integer', () => {
beforeEach(function() {
this.User = this.sequelize.define('User', {
aNumber: DataTypes.INTEGER
});
return this.User.sync({ force: true });
});
it('positive', function() {
const User = this.User;
return User.create({ aNumber: 2147483647 }).then(user => {
expect(user.aNumber).to.equal(2147483647);
return User.findOne({ where: { aNumber: 2147483647 } }).then(_user => {
expect(_user.aNumber).to.equal(2147483647);
});
});
});
it('negative', function() {
const User = this.User;
return User.create({ aNumber: -2147483647 }).then(user => {
expect(user.aNumber).to.equal(-2147483647);
return User.findOne({ where: { aNumber: -2147483647 } }).then(_user => {
expect(_user.aNumber).to.equal(-2147483647);
});
});
});
});
describe('bigint', () => {
beforeEach(function() {
this.User = this.sequelize.define('User', {
aNumber: DataTypes.BIGINT
});
return this.User.sync({ force: true });
});
it('positive', function() {
const User = this.User;
return User.create({ aNumber: '9223372036854775807' }).then(user => {
expect(user.aNumber).to.equal('9223372036854775807');
return User.findOne({ where: { aNumber: '9223372036854775807' } }).then(
_user => {
return expect(_user.aNumber.toString()).to.equal(
'9223372036854775807');
});
});
});
it('negative', function() {
const User = this.User;
return User.create({ aNumber: '-9223372036854775807' }).then(user => {
expect(user.aNumber).to.equal('-9223372036854775807');
return User.findOne(
{ where: { aNumber: '-9223372036854775807' } }).then(_user => {
return expect(_user.aNumber.toString()).to.equal(
'-9223372036854775807');
});
});
});
});
});
it('should save geometry correctly', function() {
const point = { type: 'Point', coordinates: [39.807222, -76.984722] };
return this.User.create(
{ username: 'user', email: 'foo@bar.com', location: point }).then(
newUser => {
expect(newUser.location).to.deep.eql(point);
});
});
it('should update geometry correctly', function() {
const User = this.User;
const point1 = { type: 'Point', coordinates: [39.807222, -76.984722] };
const point2 = { type: 'Point', coordinates: [39.828333, -77.232222] };
return User.create(
{ username: 'user', email: 'foo@bar.com', location: point1 })
.then(oldUser => {
return User.update({ location: point2 },
{ where: { username: oldUser.username } })
.then(() => {
return User.findOne({ where: { username: oldUser.username } });
})
.then(updatedUser => {
expect(updatedUser.location).to.deep.eql(point2);
});
});
});
it('should read geometry correctly', function() {
const User = this.User;
const point = { type: 'Point', coordinates: [39.807222, -76.984722] };
return User.create(
{ username: 'user', email: 'foo@bar.com', location: point }).then(
user => {
return User.findOne({ where: { username: user.username } });
}).then(user => {
expect(user.location).to.deep.eql(point);
});
});
});