Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit feb6d69

Browse files
committed
test: Add further tests for our API server, improve indexes() test
* Added tests for tables(), webpage() * Also improve reliability of indexes() test
1 parent b6b2247 commit feb6d69

File tree

1 file changed

+61
-5
lines changed

1 file changed

+61
-5
lines changed

cypress/e2e/2-api/api.cy.js

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,14 @@ describe('api tests', () => {
223223

224224
// Needs an extra step, due to the structure of the returned JSON
225225
let temp = JSON.parse(response.body)
226-
let jsonBody = temp[0]
227226

228-
expect(jsonBody).to.have.property('name', 'Candidate_Information_Candidate_First_Pref_Votes_idx')
229-
expect(jsonBody).to.have.property('table', 'Candidate_Information')
227+
let jsonBody = temp[0]
228+
expect(jsonBody).to.have.property('name')
229+
expect(jsonBody).to.have.property('table')
230230

231231
let columns = jsonBody.columns[0]
232-
expect(columns).to.have.property('id', 0)
233-
expect(columns).to.have.property('name', 'Candidate_First_Pref_Votes')
232+
expect(columns).to.have.property('id')
233+
expect(columns).to.have.property('name')
234234
}
235235
)
236236
})
@@ -285,4 +285,60 @@ describe('api tests', () => {
285285
}
286286
)
287287
})
288+
289+
// Tables
290+
// Equivalent curl command:
291+
// curl -k -F apikey="2MXwA5jGZkIQ3UNEcKsuDNSPMlx" \
292+
// -F dbowner="default" -F dbname="Assembly Election 2017.sqlite" \
293+
// https://localhost:9444/v1/tables
294+
it('tables', () => {
295+
cy.request({
296+
method: 'POST',
297+
url: 'https://localhost:9444/v1/tables',
298+
form: true,
299+
body: {
300+
apikey: '2MXwA5jGZkIQ3UNEcKsuDNSPMlx',
301+
dbowner: 'default',
302+
dbname: 'Assembly Election 2017.sqlite'
303+
},
304+
}).then(
305+
(response) => {
306+
expect(response.status).to.eq(200)
307+
308+
let jsonBody = JSON.parse(response.body)
309+
expect(jsonBody).to.have.members([
310+
"Candidate_Information",
311+
"Constituency_Turnout_Information",
312+
"Elected_Candidates"
313+
]
314+
)
315+
}
316+
)
317+
})
318+
319+
// Webpage
320+
// Equivalent curl command:
321+
// curl -k -F apikey="2MXwA5jGZkIQ3UNEcKsuDNSPMlx" \
322+
// -F dbowner="default" -F dbname="Assembly Election 2017.sqlite" \
323+
// https://localhost:9444/v1/webpage
324+
it('webpage', () => {
325+
cy.request({
326+
method: 'POST',
327+
url: 'https://localhost:9444/v1/webpage',
328+
form: true,
329+
body: {
330+
apikey: '2MXwA5jGZkIQ3UNEcKsuDNSPMlx',
331+
dbowner: 'default',
332+
dbname: 'Assembly Election 2017.sqlite'
333+
},
334+
}).then(
335+
(response) => {
336+
expect(response.status).to.eq(200)
337+
338+
let jsonBody = JSON.parse(response.body)
339+
expect(jsonBody).to.have.property('web_page')
340+
expect(jsonBody.web_page).to.match(/.*\/default\/Assembly\ Election\ 2017\.sqlite$/)
341+
}
342+
)
343+
})
288344
})

0 commit comments

Comments
 (0)