@@ -122,7 +122,7 @@ describe('api tests', () => {
122122 ( response ) => {
123123 expect ( response . status ) . to . eq ( 200 )
124124 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' ] )
126126 }
127127 )
128128 } )
@@ -158,7 +158,8 @@ describe('api tests', () => {
158158 } ) . then (
159159 ( response ) => {
160160 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' ] )
162163
163164 // Restore the contents of the database
164165 cy . request ( '/x/test/seed' )
@@ -168,6 +169,84 @@ describe('api tests', () => {
168169 )
169170 } )
170171
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+
171250 // Download
172251 // Equivalent curl command:
173252 // curl -k -F apikey="2MXwA5jGZkIQ3UNEcKsuDNSPMlx" \
@@ -313,7 +392,6 @@ describe('api tests', () => {
313392 } ) . then (
314393 ( response ) => {
315394 expect ( response . status ) . to . eq ( 200 )
316-
317395 let jsonBody = JSON . parse ( response . body )
318396 expect ( jsonBody [ 0 ] [ 0 ] ) . to . have . property ( 'Name' , 'Firstname' )
319397 expect ( jsonBody [ 0 ] [ 0 ] ) . to . have . property ( 'Type' , 3 )
@@ -358,7 +436,6 @@ describe('api tests', () => {
358436 } ) . then (
359437 ( response ) => {
360438 expect ( response . status ) . to . eq ( 200 )
361-
362439 let jsonBody = JSON . parse ( response . body )
363440 expect ( jsonBody ) . to . have . property ( 'Some release name' )
364441 expect ( jsonBody [ 'Some release name' ] ) . to . include . keys ( [ 'commit' , 'date' ] )
@@ -388,7 +465,6 @@ describe('api tests', () => {
388465 } ) . then (
389466 ( response ) => {
390467 expect ( response . status ) . to . eq ( 200 )
391-
392468 let jsonBody = JSON . parse ( response . body )
393469 expect ( jsonBody ) . to . have . members ( [
394470 "Candidate_Information" ,
@@ -432,7 +508,6 @@ describe('api tests', () => {
432508 } ) . then (
433509 ( response ) => {
434510 expect ( response . status ) . to . eq ( 200 )
435-
436511 let jsonBody = JSON . parse ( response . body )
437512 expect ( jsonBody ) . to . have . property ( 'Some tag name' )
438513 expect ( jsonBody [ 'Some tag name' ] ) . to . include . keys ( [ 'commit' , 'date' ] )
@@ -483,6 +558,33 @@ describe('api tests', () => {
483558 } )
484559 } )
485560
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+
486588 // Webpage
487589 // Equivalent curl command:
488590 // curl -k -F apikey="2MXwA5jGZkIQ3UNEcKsuDNSPMlx" \
@@ -501,7 +603,6 @@ describe('api tests', () => {
501603 } ) . then (
502604 ( response ) => {
503605 expect ( response . status ) . to . eq ( 200 )
504-
505606 let jsonBody = JSON . parse ( response . body )
506607 expect ( jsonBody ) . to . have . property ( 'web_page' )
507608 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