@@ -12,13 +12,13 @@ describe('Parse.Polygon testing', () => {
12
12
const coords = [ [ 0 , 0 ] , [ 0 , 1 ] , [ 1 , 1 ] , [ 1 , 0 ] ] ;
13
13
const closed = [ [ 0 , 0 ] , [ 0 , 1 ] , [ 1 , 1 ] , [ 1 , 0 ] , [ 0 , 0 ] ] ;
14
14
const obj = new TestObject ( ) ;
15
- obj . set ( 'polygon' , { __type : ' Polygon' , coordinates : coords } ) ;
15
+ obj . set ( 'polygon' , new Parse . Polygon ( coords ) ) ;
16
16
return obj . save ( ) . then ( ( ) => {
17
17
const query = new Parse . Query ( TestObject ) ;
18
18
return query . get ( obj . id ) ;
19
19
} ) . then ( ( result ) => {
20
20
const polygon = result . get ( 'polygon' ) ;
21
- equal ( polygon . __type , 'Polygon' ) ;
21
+ equal ( polygon instanceof Parse . Polygon , true ) ;
22
22
equal ( polygon . coordinates , closed ) ;
23
23
done ( ) ;
24
24
} , done . fail ) ;
@@ -27,13 +27,13 @@ describe('Parse.Polygon testing', () => {
27
27
it ( 'polygon save closed path' , ( done ) => {
28
28
const coords = [ [ 0 , 0 ] , [ 0 , 1 ] , [ 1 , 1 ] , [ 1 , 0 ] , [ 0 , 0 ] ] ;
29
29
const obj = new TestObject ( ) ;
30
- obj . set ( 'polygon' , { __type : ' Polygon' , coordinates : coords } ) ;
30
+ obj . set ( 'polygon' , new Parse . Polygon ( coords ) ) ;
31
31
return obj . save ( ) . then ( ( ) => {
32
32
const query = new Parse . Query ( TestObject ) ;
33
33
return query . get ( obj . id ) ;
34
34
} ) . then ( ( result ) => {
35
35
const polygon = result . get ( 'polygon' ) ;
36
- equal ( polygon . __type , 'Polygon' ) ;
36
+ equal ( polygon instanceof Parse . Polygon , true ) ;
37
37
equal ( polygon . coordinates , coords ) ;
38
38
done ( ) ;
39
39
} , done . fail ) ;
@@ -42,8 +42,8 @@ describe('Parse.Polygon testing', () => {
42
42
it ( 'polygon equalTo (open/closed) path' , ( done ) => {
43
43
const openPoints = [ [ 0 , 0 ] , [ 0 , 1 ] , [ 1 , 1 ] , [ 1 , 0 ] ] ;
44
44
const closedPoints = [ [ 0 , 0 ] , [ 0 , 1 ] , [ 1 , 1 ] , [ 1 , 0 ] , [ 0 , 0 ] ] ;
45
- const openPolygon = { __type : ' Polygon' , coordinates : openPoints } ;
46
- const closedPolygon = { __type : ' Polygon' , coordinates : closedPoints } ;
45
+ const openPolygon = new Parse . Polygon ( openPoints ) ;
46
+ const closedPolygon = new Parse . Polygon ( closedPoints ) ;
47
47
const obj = new TestObject ( ) ;
48
48
obj . set ( 'polygon' , openPolygon ) ;
49
49
return obj . save ( ) . then ( ( ) => {
@@ -52,24 +52,24 @@ describe('Parse.Polygon testing', () => {
52
52
return query . find ( ) ;
53
53
} ) . then ( ( results ) => {
54
54
const polygon = results [ 0 ] . get ( 'polygon' ) ;
55
- equal ( polygon . __type , 'Polygon' ) ;
55
+ equal ( polygon instanceof Parse . Polygon , true ) ;
56
56
equal ( polygon . coordinates , closedPoints ) ;
57
57
const query = new Parse . Query ( TestObject ) ;
58
58
query . equalTo ( 'polygon' , closedPolygon ) ;
59
59
return query . find ( ) ;
60
60
} ) . then ( ( results ) => {
61
61
const polygon = results [ 0 ] . get ( 'polygon' ) ;
62
- equal ( polygon . __type , 'Polygon' ) ;
62
+ equal ( polygon instanceof Parse . Polygon , true ) ;
63
63
equal ( polygon . coordinates , closedPoints ) ;
64
64
done ( ) ;
65
65
} , done . fail ) ;
66
66
} ) ;
67
67
68
68
it ( 'polygon update' , ( done ) => {
69
69
const oldCoords = [ [ 0 , 0 ] , [ 0 , 1 ] , [ 1 , 1 ] , [ 1 , 0 ] ] ;
70
- const oldPolygon = { __type : ' Polygon' , coordinates : oldCoords } ;
70
+ const oldPolygon = new Parse . Polygon ( oldCoords ) ;
71
71
const newCoords = [ [ 2 , 2 ] , [ 2 , 3 ] , [ 3 , 3 ] , [ 3 , 2 ] ] ;
72
- const newPolygon = { __type : ' Polygon' , coordinates : newCoords } ;
72
+ const newPolygon = new Parse . Polygon ( newCoords ) ;
73
73
const obj = new TestObject ( ) ;
74
74
obj . set ( 'polygon' , oldPolygon ) ;
75
75
return obj . save ( ) . then ( ( ) => {
@@ -81,7 +81,7 @@ describe('Parse.Polygon testing', () => {
81
81
} ) . then ( ( result ) => {
82
82
const polygon = result . get ( 'polygon' ) ;
83
83
newCoords . push ( newCoords [ 0 ] ) ;
84
- equal ( polygon . __type , 'Polygon' ) ;
84
+ equal ( polygon instanceof Parse . Polygon , true ) ;
85
85
equal ( polygon . coordinates , newCoords ) ;
86
86
done ( ) ;
87
87
} , done . fail ) ;
@@ -100,28 +100,29 @@ describe('Parse.Polygon testing', () => {
100
100
it ( 'polygon three points minimum' , ( done ) => {
101
101
const coords = [ [ 0 , 0 ] ] ;
102
102
const obj = new TestObject ( ) ;
103
+ // use raw so we test the server validates properly
103
104
obj . set ( 'polygon' , { __type : 'Polygon' , coordinates : coords } ) ;
104
105
obj . save ( ) . then ( done . fail , done ) ;
105
106
} ) ;
106
107
107
108
it ( 'polygon three different points minimum' , ( done ) => {
108
109
const coords = [ [ 0 , 0 ] , [ 0 , 1 ] , [ 0 , 0 ] ] ;
109
110
const obj = new TestObject ( ) ;
110
- obj . set ( 'polygon' , { __type : ' Polygon' , coordinates : coords } ) ;
111
+ obj . set ( 'polygon' , new Parse . Polygon ( coords ) ) ;
111
112
obj . save ( ) . then ( done . fail , done ) ;
112
113
} ) ;
113
114
114
115
it ( 'polygon counterclockwise' , ( done ) => {
115
116
const coords = [ [ 1 , 1 ] , [ 0 , 1 ] , [ 0 , 0 ] , [ 1 , 0 ] ] ;
116
117
const closed = [ [ 1 , 1 ] , [ 0 , 1 ] , [ 0 , 0 ] , [ 1 , 0 ] , [ 1 , 1 ] ] ;
117
118
const obj = new TestObject ( ) ;
118
- obj . set ( 'polygon' , { __type : ' Polygon' , coordinates : coords } ) ;
119
+ obj . set ( 'polygon' , new Parse . Polygon ( coords ) ) ;
119
120
obj . save ( ) . then ( ( ) => {
120
121
const query = new Parse . Query ( TestObject ) ;
121
122
return query . get ( obj . id ) ;
122
123
} ) . then ( ( result ) => {
123
124
const polygon = result . get ( 'polygon' ) ;
124
- equal ( polygon . __type , 'Polygon' ) ;
125
+ equal ( polygon instanceof Parse . Polygon , true ) ;
125
126
equal ( polygon . coordinates , closed ) ;
126
127
done ( ) ;
127
128
} , done . fail ) ;
@@ -131,9 +132,9 @@ describe('Parse.Polygon testing', () => {
131
132
const points1 = [ [ 0 , 0 ] , [ 0 , 1 ] , [ 1 , 1 ] , [ 1 , 0 ] ] ;
132
133
const points2 = [ [ 0 , 0 ] , [ 0 , 2 ] , [ 2 , 2 ] , [ 2 , 0 ] ] ;
133
134
const points3 = [ [ 10 , 10 ] , [ 10 , 15 ] , [ 15 , 15 ] , [ 15 , 10 ] , [ 10 , 10 ] ] ;
134
- const polygon1 = { __type : ' Polygon' , coordinates : points1 } ;
135
- const polygon2 = { __type : ' Polygon' , coordinates : points2 } ;
136
- const polygon3 = { __type : ' Polygon' , coordinates : points3 } ;
135
+ const polygon1 = new Parse . Polygon ( points1 ) ;
136
+ const polygon2 = new Parse . Polygon ( points2 ) ;
137
+ const polygon3 = new Parse . Polygon ( points3 ) ;
137
138
const obj1 = new TestObject ( { location : polygon1 } ) ;
138
139
const obj2 = new TestObject ( { location : polygon2 } ) ;
139
140
const obj3 = new TestObject ( { location : polygon3 } ) ;
@@ -161,7 +162,7 @@ describe('Parse.Polygon testing', () => {
161
162
162
163
it ( 'polygonContain invalid input' , ( done ) => {
163
164
const points = [ [ 0 , 0 ] , [ 0 , 1 ] , [ 1 , 1 ] , [ 1 , 0 ] ] ;
164
- const polygon = { __type : ' Polygon' , coordinates : points } ;
165
+ const polygon = new Parse . Polygon ( points ) ;
165
166
const obj = new TestObject ( { location : polygon } ) ;
166
167
obj . save ( ) . then ( ( ) => {
167
168
const where = {
@@ -184,7 +185,7 @@ describe('Parse.Polygon testing', () => {
184
185
185
186
it ( 'polygonContain invalid geoPoint' , ( done ) => {
186
187
const points = [ [ 0 , 0 ] , [ 0 , 1 ] , [ 1 , 1 ] , [ 1 , 0 ] ] ;
187
- const polygon = { __type : ' Polygon' , coordinates : points } ;
188
+ const polygon = new Parse . Polygon ( points ) ;
188
189
const obj = new TestObject ( { location : polygon } ) ;
189
190
obj . save ( ) . then ( ( ) => {
190
191
const where = {
@@ -209,6 +210,7 @@ describe('Parse.Polygon testing', () => {
209
210
describe_only_db ( 'mongo' ) ( 'Parse.Polygon testing' , ( ) => {
210
211
it ( 'support 2d and 2dsphere' , ( done ) => {
211
212
const coords = [ [ 0 , 0 ] , [ 0 , 1 ] , [ 1 , 1 ] , [ 1 , 0 ] , [ 0 , 0 ] ] ;
213
+ // testings against REST API, use raw formats
212
214
const polygon = { __type : 'Polygon' , coordinates : coords } ;
213
215
const location = { __type : 'GeoPoint' , latitude :10 , longitude :10 } ;
214
216
const databaseAdapter = new MongoStorageAdapter ( { uri : mongoURI } ) ;
@@ -256,7 +258,7 @@ describe_only_db('mongo')('Parse.Polygon testing', () => {
256
258
it ( 'polygon loop is not valid' , ( done ) => {
257
259
const coords = [ [ 0 , 0 ] , [ 0 , 1 ] , [ 1 , 0 ] , [ 1 , 1 ] ] ;
258
260
const obj = new TestObject ( ) ;
259
- obj . set ( 'polygon' , { __type : ' Polygon' , coordinates : coords } ) ;
261
+ obj . set ( 'polygon' , new Parse . Polygon ( coords ) ) ;
260
262
obj . save ( ) . then ( done . fail , done ) ;
261
263
} ) ;
262
264
} ) ;
0 commit comments