1
+ import path from "path" ;
2
+
1
3
describe ( 'api tests' , ( ) => {
2
4
before ( ( ) => {
3
5
// Seed data
@@ -100,4 +102,187 @@ describe('api tests', () => {
100
102
}
101
103
)
102
104
} )
105
+
106
+ // Databases
107
+ // Equivalent curl command:
108
+ // curl -k -F apikey="2MXwA5jGZkIQ3UNEcKsuDNSPMlx" \
109
+ // https://localhost:9444/v1/databases
110
+ it ( 'databases' , ( ) => {
111
+ cy . request ( {
112
+ method : 'POST' ,
113
+ url : 'https://localhost:9444/v1/databases' ,
114
+ form : true ,
115
+ body : {
116
+ apikey : '2MXwA5jGZkIQ3UNEcKsuDNSPMlx'
117
+ } ,
118
+ } ) . then (
119
+ ( response ) => {
120
+ expect ( response . status ) . to . eq ( 200 )
121
+ let jsonBody = JSON . parse ( response . body )
122
+ expect ( jsonBody ) . to . include . members ( [ "Assembly Election 2017.sqlite" ] )
123
+ }
124
+ )
125
+ } )
126
+
127
+ // Delete
128
+ // Equivalent curl command:
129
+ // curl -k -F apikey="2MXwA5jGZkIQ3UNEcKsuDNSPMlx" \
130
+ // -F dbname="Assembly Election 2017.sqlite" \
131
+ // https://localhost:9444/v1/delete
132
+ it ( 'delete' , ( ) => {
133
+ cy . request ( {
134
+ method : 'POST' ,
135
+ url : 'https://localhost:9444/v1/delete' ,
136
+ form : true ,
137
+ body : {
138
+ apikey : '2MXwA5jGZkIQ3UNEcKsuDNSPMlx' ,
139
+ dbname : 'Assembly Election 2017.sqlite' ,
140
+ } ,
141
+ } ) . then (
142
+ ( response ) => {
143
+ expect ( response . status ) . to . eq ( 200 )
144
+ let jsonBody = JSON . parse ( response . body )
145
+ expect ( jsonBody ) . to . have . property ( 'status' , 'OK' )
146
+
147
+ // Verify the database is no longer present
148
+ cy . request ( {
149
+ method : 'POST' ,
150
+ url : 'https://localhost:9444/v1/databases' ,
151
+ form : true ,
152
+ body : {
153
+ apikey : '2MXwA5jGZkIQ3UNEcKsuDNSPMlx'
154
+ } ,
155
+ } ) . then (
156
+ ( response ) => {
157
+ expect ( response . status ) . to . eq ( 200 )
158
+ expect ( response . body ) . to . eq ( 'null' )
159
+
160
+ // Restore the contents of the database
161
+ cy . request ( '/x/test/seed' )
162
+ }
163
+ )
164
+ }
165
+ )
166
+ } )
167
+
168
+ // Download
169
+ // Equivalent curl command:
170
+ // curl -k -F apikey="2MXwA5jGZkIQ3UNEcKsuDNSPMlx" \
171
+ // -F dbowner="default" -F dbname="Assembly Election 2017.sqlite" \
172
+ // https://localhost:9444/v1/download
173
+ const downloadsFolder = Cypress . config ( 'downloadsFolder' )
174
+ it ( 'download' , ( ) => {
175
+ cy . request ( {
176
+ method : 'POST' ,
177
+ url : 'https://localhost:9444/v1/download' ,
178
+ form : true ,
179
+ body : {
180
+ apikey : '2MXwA5jGZkIQ3UNEcKsuDNSPMlx' ,
181
+ dbowner : 'default' ,
182
+ dbname : 'Assembly Election 2017.sqlite' ,
183
+ } ,
184
+ } ) . then (
185
+ ( response ) => {
186
+ expect ( response . status ) . to . eq ( 200 )
187
+
188
+ // Save the database to local disk
189
+ const db = path . join ( downloadsFolder , 'Assembly Election 2017.sqlite' )
190
+ // FIXME: cy.writeFile() isn't writing the full file out to disk, even though the server
191
+ // is definitely sending it (as evidenced by curl having no issues). It would be
192
+ // good to figure out wtf is causing this problem, then fix it and write a more
193
+ // thorough cy.readFile() test.
194
+ cy . writeFile ( db , response . body , 'binary' )
195
+
196
+ // Verify the downloaded file is ok
197
+ cy . readFile ( db , 'binary' , { timeout : 5000 } ) . should ( 'have.length.gt' , 512 )
198
+
199
+ // Remove the downloaded file
200
+ cy . task ( 'rmFile' , { path : db } )
201
+ }
202
+ )
203
+ } )
204
+
205
+ // Indexes
206
+ // Equivalent curl command:
207
+ // curl -k -F apikey="2MXwA5jGZkIQ3UNEcKsuDNSPMlx" \
208
+ // -F dbowner="default" -F dbname="Assembly Election 2017.sqlite" \
209
+ // https://localhost:9444/v1/indexes
210
+ it ( 'indexes' , ( ) => {
211
+ cy . request ( {
212
+ method : 'POST' ,
213
+ url : 'https://localhost:9444/v1/indexes' ,
214
+ form : true ,
215
+ body : {
216
+ apikey : '2MXwA5jGZkIQ3UNEcKsuDNSPMlx' ,
217
+ dbowner : 'default' ,
218
+ dbname : 'Assembly Election 2017.sqlite'
219
+ } ,
220
+ } ) . then (
221
+ ( response ) => {
222
+ expect ( response . status ) . to . eq ( 200 )
223
+
224
+ // Needs an extra step, due to the structure of the returned JSON
225
+ let temp = JSON . parse ( response . body )
226
+ let jsonBody = temp [ 0 ]
227
+
228
+ expect ( jsonBody ) . to . have . property ( 'name' , 'Candidate_Information_Candidate_First_Pref_Votes_idx' )
229
+ expect ( jsonBody ) . to . have . property ( 'table' , 'Candidate_Information' )
230
+
231
+ let columns = jsonBody . columns [ 0 ]
232
+ expect ( columns ) . to . have . property ( 'id' , 0 )
233
+ expect ( columns ) . to . have . property ( 'name' , 'Candidate_First_Pref_Votes' )
234
+ }
235
+ )
236
+ } )
237
+
238
+ // Metadata
239
+ // Equivalent curl command:
240
+ // curl -k -F apikey="2MXwA5jGZkIQ3UNEcKsuDNSPMlx" \
241
+ // -F dbowner="default" -F dbname="Assembly Election 2017.sqlite" \
242
+ // https://localhost:9444/v1/metadata
243
+ it ( 'metadata' , ( ) => {
244
+ cy . request ( {
245
+ method : 'POST' ,
246
+ url : 'https://localhost:9444/v1/metadata' ,
247
+ form : true ,
248
+ body : {
249
+ apikey : '2MXwA5jGZkIQ3UNEcKsuDNSPMlx' ,
250
+ dbowner : 'default' ,
251
+ dbname : 'Assembly Election 2017.sqlite'
252
+ } ,
253
+ } ) . then (
254
+ ( response ) => {
255
+ expect ( response . status ) . to . eq ( 200 )
256
+
257
+ let jsonBody = JSON . parse ( response . body )
258
+ expect ( jsonBody ) . to . have . property ( 'default_branch' , 'main' )
259
+
260
+ // Test the "branches" structure
261
+ let branchesMain = jsonBody . branches . main
262
+ expect ( branchesMain ) . to . have . property ( 'commit_count' , 1 )
263
+ expect ( branchesMain ) . to . have . property ( 'description' , '' )
264
+
265
+ // Test the "commits" structure
266
+ let commitID = Object . keys ( jsonBody . commits )
267
+ let commitData = jsonBody . commits [ commitID ]
268
+ expect ( commitData ) . to . have . property ( 'author_email' , '[email protected] ' )
269
+ expect ( commitData ) . to . have . property ( 'author_name' , 'Default system user' )
270
+ expect ( commitData ) . to . have . property ( 'committer_email' , '' )
271
+ expect ( commitData ) . to . have . property ( 'committer_name' , '' )
272
+ expect ( commitData ) . to . have . property ( 'message' , 'Initial commit' )
273
+ expect ( commitData ) . to . have . property ( 'other_parents' , null )
274
+ expect ( commitData ) . to . have . property ( 'parent' , '' )
275
+ expect ( commitData ) . to . include . keys ( [ 'id' , 'timestamp' , 'tree' ] )
276
+
277
+ // Test the "tree" structure
278
+ let entries = commitData . tree . entries [ 0 ]
279
+ expect ( entries ) . to . have . property ( 'entry_type' , 'db' )
280
+ expect ( entries ) . to . have . property ( 'licence' , '9348ddfd44da5a127c59141981954746a860ec8e03e0412cf3af7134af0f97e2' )
281
+ expect ( entries ) . to . have . property ( 'name' , 'Assembly Election 2017.sqlite' )
282
+ expect ( entries ) . to . have . property ( 'sha256' , '4244d55013359c6476d06c045700139629ecfd2752ffad141984ba14ecafd17e' )
283
+ expect ( entries ) . to . have . property ( 'size' , 57344 )
284
+ expect ( entries ) . to . include . keys ( [ 'last_modified' ] )
285
+ }
286
+ )
287
+ } )
103
288
} )
0 commit comments