geography.test.js
6.81 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
'use strict';
const chai = require('chai'),
expect = chai.expect,
Support = require(__dirname + '/../support'),
DataTypes = require(__dirname + '/../../../lib/data-types');
const current = Support.sequelize;
describe(Support.getTestDialectTeaser('Model'), () => {
if (current.dialect.supports.GEOGRAPHY) {
describe('GEOGRAPHY', () => {
beforeEach(function() {
this.User = this.sequelize.define('User', {
username: DataTypes.STRING,
geography: DataTypes.GEOGRAPHY
});
return this.User.sync({ force: true });
});
it('works with aliases fields', function() {
const Pub = this.sequelize.define('Pub', {
location: {field: 'coordinates', type: DataTypes.GEOGRAPHY}
}),
point = {type: 'Point', coordinates: [39.807222, -76.984722]};
return Pub.sync({ force: true }).then(() => {
return Pub.create({location: point});
}).then(pub => {
expect(pub).not.to.be.null;
expect(pub.location).to.be.deep.eql(point);
});
});
it('should create a geography object', function() {
const User = this.User;
const point = { type: 'Point', coordinates: [39.807222, -76.984722]};
return User.create({username: 'username', geography: point }).then(newUser => {
expect(newUser).not.to.be.null;
expect(newUser.geography).to.be.deep.eql(point);
});
});
it('should update a geography object', function() {
const User = this.User;
const point1 = { type: 'Point', coordinates: [39.807222, -76.984722]},
point2 = { type: 'Point', coordinates: [49.807222, -86.984722]};
const props = {username: 'username', geography: point1};
return User.create(props).then(() => {
return User.update({geography: point2}, {where: {username: props.username}});
}).then(() => {
return User.findOne({where: {username: props.username}});
}).then(user => {
expect(user.geography).to.be.deep.eql(point2);
});
});
});
describe('GEOGRAPHY(POINT)', () => {
beforeEach(function() {
this.User = this.sequelize.define('User', {
username: DataTypes.STRING,
geography: DataTypes.GEOGRAPHY('POINT')
});
return this.User.sync({ force: true });
});
it('should create a geography object', function() {
const User = this.User;
const point = { type: 'Point', coordinates: [39.807222, -76.984722]};
return User.create({username: 'username', geography: point }).then(newUser => {
expect(newUser).not.to.be.null;
expect(newUser.geography).to.be.deep.eql(point);
});
});
it('should update a geography object', function() {
const User = this.User;
const point1 = { type: 'Point', coordinates: [39.807222, -76.984722]},
point2 = { type: 'Point', coordinates: [49.807222, -86.984722]};
const props = {username: 'username', geography: point1};
return User.create(props).then(() => {
return User.update({geography: point2}, {where: {username: props.username}});
}).then(() => {
return User.findOne({where: {username: props.username}});
}).then(user => {
expect(user.geography).to.be.deep.eql(point2);
});
});
});
describe('GEOGRAPHY(LINESTRING)', () => {
beforeEach(function() {
this.User = this.sequelize.define('User', {
username: DataTypes.STRING,
geography: DataTypes.GEOGRAPHY('LINESTRING')
});
return this.User.sync({ force: true });
});
it('should create a geography object', function() {
const User = this.User;
const point = { type: 'LineString', 'coordinates': [ [100.0, 0.0], [101.0, 1.0] ] };
return User.create({username: 'username', geography: point }).then(newUser => {
expect(newUser).not.to.be.null;
expect(newUser.geography).to.be.deep.eql(point);
});
});
it('should update a geography object', function() {
const User = this.User;
const point1 = { type: 'LineString', coordinates: [ [100.0, 0.0], [101.0, 1.0] ] },
point2 = { type: 'LineString', coordinates: [ [101.0, 0.0], [102.0, 1.0] ] };
const props = {username: 'username', geography: point1};
return User.create(props).then(() => {
return User.update({geography: point2}, {where: {username: props.username}});
}).then(() => {
return User.findOne({where: {username: props.username}});
}).then(user => {
expect(user.geography).to.be.deep.eql(point2);
});
});
});
describe('GEOGRAPHY(POLYGON)', () => {
beforeEach(function() {
this.User = this.sequelize.define('User', {
username: DataTypes.STRING,
geography: DataTypes.GEOGRAPHY('POLYGON')
});
return this.User.sync({ force: true });
});
it('should create a geography object', function() {
const User = this.User;
const point = { type: 'Polygon', coordinates: [
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
[100.0, 1.0], [100.0, 0.0] ]
]};
return User.create({username: 'username', geography: point }).then(newUser => {
expect(newUser).not.to.be.null;
expect(newUser.geography).to.be.deep.eql(point);
});
});
it('should update a geography object', function() {
const User = this.User;
const polygon1 = { type: 'Polygon', coordinates: [
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]
]},
polygon2 = { type: 'Polygon', coordinates: [
[ [100.0, 0.0], [102.0, 0.0], [102.0, 1.0],
[100.0, 1.0], [100.0, 0.0] ]
]};
const props = {username: 'username', geography: polygon1};
return User.create(props).then(() => {
return User.update({geography: polygon2}, {where: {username: props.username}});
}).then(() => {
return User.findOne({where: {username: props.username}});
}).then(user => {
expect(user.geography).to.be.deep.eql(polygon2);
});
});
});
describe('sql injection attacks', () => {
beforeEach(function() {
this.Model = this.sequelize.define('Model', {
location: DataTypes.GEOGRAPHY
});
return this.sequelize.sync({ force: true });
});
it('should properly escape the single quotes', function() {
return this.Model.create({
location: {
type: 'Point',
properties: {
exploit: "'); DELETE YOLO INJECTIONS; -- "
},
coordinates: [39.807222, -76.984722]
}
});
});
});
}
});