@@ -122,7 +122,7 @@ describe('api tests', () => {
122
122
( response ) => {
123
123
expect ( response . status ) . to . eq ( 200 )
124
124
let jsonBody = JSON . parse ( response . body )
125
- expect ( jsonBody ) . to . include . members ( [ "Assembly Election 2017.sqlite" ] )
125
+ expect ( jsonBody ) . to . include . members ( [ "Assembly Election 2017.sqlite" , 'Assembly Election 2017 with view.sqlite' ] )
126
126
}
127
127
)
128
128
} )
@@ -158,7 +158,8 @@ describe('api tests', () => {
158
158
} ) . then (
159
159
( response ) => {
160
160
expect ( response . status ) . to . eq ( 200 )
161
- expect ( response . body ) . to . eq ( 'null' )
161
+ let jsonBody = JSON . parse ( response . body )
162
+ expect ( jsonBody ) . to . include . members ( [ 'Assembly Election 2017 with view.sqlite' ] )
162
163
163
164
// Restore the contents of the database
164
165
cy . request ( '/x/test/seed' )
@@ -168,6 +169,84 @@ describe('api tests', () => {
168
169
)
169
170
} )
170
171
172
+ // Diff
173
+ // Equivalent curl command:
174
+ // curl -k -F apikey="2MXwA5jGZkIQ3UNEcKsuDNSPMlx" \
175
+ // -F dbowner_a="default" -F dbname_a="Assembly Election 2017.sqlite" -F commit_a="SOME_COMMIT_ID_HERE" \
176
+ // -F dbowner_b="default" -F dbname_b="Assembly Election 2017 with view.sqlite" -F commit_b="SOME_OTHER_COMMIT_ID_HERE" \
177
+ // https://localhost:9444/v1/diff
178
+ it ( 'diff' , ( ) => {
179
+ // *** Retrieve the required commit IDs for both databases first, then call the api diff function to test it ***
180
+ let commitA , commitB ;
181
+
182
+ // Retrieve the latest commit ID from the first test database
183
+ cy . request ( {
184
+ method : 'POST' ,
185
+ url : 'https://localhost:9444/v1/commits' ,
186
+ form : true ,
187
+ body : {
188
+ apikey : '2MXwA5jGZkIQ3UNEcKsuDNSPMlx' ,
189
+ dbowner : 'default' ,
190
+ dbname : 'Assembly Election 2017.sqlite' ,
191
+ } ,
192
+ } ) . then (
193
+ ( response ) => {
194
+ expect ( response . status ) . to . eq ( 200 )
195
+ commitA = Object . keys ( JSON . parse ( response . body ) ) [ 0 ]
196
+ }
197
+ ) . then (
198
+ ( response ) => {
199
+ // Retrieve the latest commit ID from the second test database
200
+ cy . request ( {
201
+ method : 'POST' ,
202
+ url : 'https://localhost:9444/v1/commits' ,
203
+ form : true ,
204
+ body : {
205
+ apikey : '2MXwA5jGZkIQ3UNEcKsuDNSPMlx' ,
206
+ dbowner : 'default' ,
207
+ dbname : 'Assembly Election 2017 with view.sqlite' ,
208
+ } ,
209
+ } ) . then (
210
+ ( response ) => {
211
+ expect ( response . status ) . to . eq ( 200 )
212
+ commitB = Object . keys ( JSON . parse ( response . body ) ) [ 0 ]
213
+ }
214
+ ) . then (
215
+ ( response ) => {
216
+
217
+ // Now that we have the required commit IDs for each database, we call the API server diff() function to test it
218
+ cy . request ( {
219
+ method : 'POST' ,
220
+ url : 'https://localhost:9444/v1/diff' ,
221
+ form : true ,
222
+ body : {
223
+ apikey : '2MXwA5jGZkIQ3UNEcKsuDNSPMlx' ,
224
+ dbowner_a : 'default' ,
225
+ dbname_a : 'Assembly Election 2017.sqlite' ,
226
+ commit_a : commitA ,
227
+ dbowner_b : 'default' ,
228
+ dbname_b : 'Assembly Election 2017 with view.sqlite' ,
229
+ commit_b : commitB
230
+ } ,
231
+ } ) . then (
232
+ ( response ) => {
233
+ expect ( response . status ) . to . eq ( 200 )
234
+ let jsonBody = JSON . parse ( response . body )
235
+ let diff = jsonBody [ "diff" ] [ 0 ]
236
+ expect ( diff ) . to . have . property ( 'object_name' , 'Candidate_Names' )
237
+ expect ( diff ) . to . have . property ( 'object_type' , 'view' )
238
+ expect ( diff ) . to . have . property ( 'schema' )
239
+ expect ( diff . schema ) . to . have . property ( 'action_type' , 'add' )
240
+ expect ( diff . schema ) . to . have . property ( 'before' , '' )
241
+ expect ( diff . schema ) . to . have . property ( 'after' , 'CREATE VIEW "Candidate_Names" AS\n SELECT Firstname, Surname\n FROM "Candidate_Information"\n ORDER BY Surname, Firstname\n DESC' )
242
+ }
243
+ )
244
+ }
245
+ )
246
+ }
247
+ )
248
+ } )
249
+
171
250
// Download
172
251
// Equivalent curl command:
173
252
// curl -k -F apikey="2MXwA5jGZkIQ3UNEcKsuDNSPMlx" \
@@ -313,7 +392,6 @@ describe('api tests', () => {
313
392
} ) . then (
314
393
( response ) => {
315
394
expect ( response . status ) . to . eq ( 200 )
316
-
317
395
let jsonBody = JSON . parse ( response . body )
318
396
expect ( jsonBody [ 0 ] [ 0 ] ) . to . have . property ( 'Name' , 'Firstname' )
319
397
expect ( jsonBody [ 0 ] [ 0 ] ) . to . have . property ( 'Type' , 3 )
@@ -358,7 +436,6 @@ describe('api tests', () => {
358
436
} ) . then (
359
437
( response ) => {
360
438
expect ( response . status ) . to . eq ( 200 )
361
-
362
439
let jsonBody = JSON . parse ( response . body )
363
440
expect ( jsonBody ) . to . have . property ( 'Some release name' )
364
441
expect ( jsonBody [ 'Some release name' ] ) . to . include . keys ( [ 'commit' , 'date' ] )
@@ -388,7 +465,6 @@ describe('api tests', () => {
388
465
} ) . then (
389
466
( response ) => {
390
467
expect ( response . status ) . to . eq ( 200 )
391
-
392
468
let jsonBody = JSON . parse ( response . body )
393
469
expect ( jsonBody ) . to . have . members ( [
394
470
"Candidate_Information" ,
@@ -432,7 +508,6 @@ describe('api tests', () => {
432
508
} ) . then (
433
509
( response ) => {
434
510
expect ( response . status ) . to . eq ( 200 )
435
-
436
511
let jsonBody = JSON . parse ( response . body )
437
512
expect ( jsonBody ) . to . have . property ( 'Some tag name' )
438
513
expect ( jsonBody [ 'Some tag name' ] ) . to . include . keys ( [ 'commit' , 'date' ] )
@@ -483,6 +558,33 @@ describe('api tests', () => {
483
558
} )
484
559
} )
485
560
561
+ // Views
562
+ // Equivalent curl command:
563
+ // curl -k -F apikey="2MXwA5jGZkIQ3UNEcKsuDNSPMlx" \
564
+ // -F dbowner="default" -F dbname="Assembly Election 2017.sqlite" \
565
+ // https://localhost:9444/v1/views
566
+ it ( 'views' , ( ) => {
567
+ cy . request ( {
568
+ method : 'POST' ,
569
+ url : 'https://localhost:9444/v1/views' ,
570
+ form : true ,
571
+ body : {
572
+ apikey : '2MXwA5jGZkIQ3UNEcKsuDNSPMlx' ,
573
+ dbowner : 'default' ,
574
+ dbname : 'Assembly Election 2017 with view.sqlite'
575
+ } ,
576
+ } ) . then (
577
+ ( response ) => {
578
+ expect ( response . status ) . to . eq ( 200 )
579
+ let jsonBody = JSON . parse ( response . body )
580
+ expect ( jsonBody ) . to . have . members ( [
581
+ "Candidate_Names"
582
+ ]
583
+ )
584
+ }
585
+ )
586
+ } )
587
+
486
588
// Webpage
487
589
// Equivalent curl command:
488
590
// curl -k -F apikey="2MXwA5jGZkIQ3UNEcKsuDNSPMlx" \
@@ -501,7 +603,6 @@ describe('api tests', () => {
501
603
} ) . then (
502
604
( response ) => {
503
605
expect ( response . status ) . to . eq ( 200 )
504
-
505
606
let jsonBody = JSON . parse ( response . body )
506
607
expect ( jsonBody ) . to . have . property ( 'web_page' )
507
608
expect ( jsonBody . web_page ) . to . match ( / .* \/ d e f a u l t \/ A s s e m b l y \ E l e c t i o n \ 2 0 1 7 \. s q l i t e $ / )
0 commit comments