|
1 | 1 | import path from "path";
|
2 | 2 |
|
| 3 | +// TODO: Looks like we don't have API functions yet to create branches, tags, or releases |
| 4 | +// Those could be useful to add |
| 5 | + |
3 | 6 | describe('api tests', () => {
|
4 | 7 | before(() => {
|
5 | 8 | // Seed data
|
@@ -286,6 +289,87 @@ describe('api tests', () => {
|
286 | 289 | )
|
287 | 290 | })
|
288 | 291 |
|
| 292 | + // Query |
| 293 | + // Equivalent curl command: |
| 294 | + // curl -k -F apikey="2MXwA5jGZkIQ3UNEcKsuDNSPMlx" \ |
| 295 | + // -F dbowner="default" -F dbname="Assembly Election 2017.sqlite" \ |
| 296 | + // -F sql="U0VMRUNUIGNvdW50KCopIEZST00gQ2FuZGlkYXRlX0luZm9ybWF0aW9u" \ |
| 297 | + // https://localhost:9444/v1/query |
| 298 | + // Note: the sql argument above is the base64 encoding of "SELECT count(*) FROM Candidate_Information" |
| 299 | + // Another useful sql is: |
| 300 | + // text: 'SELECT Firstname, Surname FROM Candidate_Information ORDER BY Surname, Firstname LIMIT 1' |
| 301 | + // base64: U0VMRUNUIEZpcnN0bmFtZSwgU3VybmFtZSBGUk9NIENhbmRpZGF0ZV9JbmZvcm1hdGlvbiBPUkRFUiBCWSBTdXJuYW1lLCBGaXJzdG5hbWUgTElNSVQgMQ== |
| 302 | + it('query', () => { |
| 303 | + cy.request({ |
| 304 | + method: 'POST', |
| 305 | + url: 'https://localhost:9444/v1/query', |
| 306 | + form: true, |
| 307 | + body: { |
| 308 | + apikey: '2MXwA5jGZkIQ3UNEcKsuDNSPMlx', |
| 309 | + dbowner: 'default', |
| 310 | + dbname: 'Assembly Election 2017.sqlite', |
| 311 | + sql: btoa('SELECT Firstname, Surname FROM Candidate_Information ORDER BY Surname, Firstname LIMIT 1') |
| 312 | + }, |
| 313 | + }).then( |
| 314 | + (response) => { |
| 315 | + expect(response.status).to.eq(200) |
| 316 | + |
| 317 | + let jsonBody = JSON.parse(response.body) |
| 318 | + expect(jsonBody[0][0]).to.have.property('Name', 'Firstname') |
| 319 | + expect(jsonBody[0][0]).to.have.property('Type', 3) |
| 320 | + expect(jsonBody[0][0]).to.have.property('Value', 'Steven') |
| 321 | + expect(jsonBody[0][1]).to.have.property('Name', 'Surname') |
| 322 | + expect(jsonBody[0][1]).to.have.property('Type', 3) |
| 323 | + expect(jsonBody[0][1]).to.have.property('Value', 'Agnew') |
| 324 | + } |
| 325 | + ) |
| 326 | + }) |
| 327 | + |
| 328 | + // Releases |
| 329 | + // Equivalent curl command: |
| 330 | + // curl -k -F apikey="2MXwA5jGZkIQ3UNEcKsuDNSPMlx" \ |
| 331 | + // -F dbowner="default" -F dbname="Assembly Election 2017.sqlite" \ |
| 332 | + // https://localhost:9444/v1/releases |
| 333 | + it('releases', () => { |
| 334 | + // Create a release, so we can test it using the API |
| 335 | + cy.visit('default/Assembly%20Election%202017.sqlite') |
| 336 | + cy.get('[data-cy="rlscnt"]').should('contain', '0') |
| 337 | + cy.get('[data-cy="commitslnk"]').click() |
| 338 | + cy.get('[data-cy="createtagrelbtn"]').click() |
| 339 | + cy.get('[data-cy="nameinput"]').type('{selectall}{backspace}').type('Some release name').should('have.value', 'Some release name') |
| 340 | + cy.get('[data-cy="relradio"]').click() |
| 341 | + cy.get('[data-cy="desctext"]').type('{selectall}{backspace}').type('Some release description').should('have.value', 'Some release description') |
| 342 | + cy.get('[data-cy="previewtab"]').click() |
| 343 | + cy.get('[data-cy="previewdiv"]').should('contain', 'Some release description') |
| 344 | + cy.get('[data-cy="createbtn"]').click() |
| 345 | + cy.visit('default/Assembly%20Election%202017.sqlite') |
| 346 | + cy.get('[data-cy="rlscnt"]').should('contain', '1') |
| 347 | + |
| 348 | + // Test the release details via the api |
| 349 | + cy.request({ |
| 350 | + method: 'POST', |
| 351 | + url: 'https://localhost:9444/v1/releases', |
| 352 | + form: true, |
| 353 | + body: { |
| 354 | + apikey: '2MXwA5jGZkIQ3UNEcKsuDNSPMlx', |
| 355 | + dbowner: 'default', |
| 356 | + dbname: 'Assembly Election 2017.sqlite' |
| 357 | + }, |
| 358 | + }).then( |
| 359 | + (response) => { |
| 360 | + expect(response.status).to.eq(200) |
| 361 | + |
| 362 | + let jsonBody = JSON.parse(response.body) |
| 363 | + expect(jsonBody).to.have.property('Some release name') |
| 364 | + expect(jsonBody['Some release name']).to.include.keys(['commit', 'date']) |
| 365 | + expect(jsonBody['Some release name']).to.have.property('description', 'Some release description') |
| 366 | + expect(jsonBody['Some release name']).to.have.property('email', '[email protected]') |
| 367 | + expect(jsonBody['Some release name']).to.have.property('name', 'Default system user') |
| 368 | + expect(jsonBody['Some release name']).to.have.property('size', 73728) |
| 369 | + } |
| 370 | + ) |
| 371 | + }) |
| 372 | + |
289 | 373 | // Tables
|
290 | 374 | // Equivalent curl command:
|
291 | 375 | // curl -k -F apikey="2MXwA5jGZkIQ3UNEcKsuDNSPMlx" \
|
@@ -316,6 +400,49 @@ describe('api tests', () => {
|
316 | 400 | )
|
317 | 401 | })
|
318 | 402 |
|
| 403 | + // Tags |
| 404 | + // Equivalent curl command: |
| 405 | + // curl -k -F apikey="2MXwA5jGZkIQ3UNEcKsuDNSPMlx" \ |
| 406 | + // -F dbowner="default" -F dbname="Assembly Election 2017.sqlite" \ |
| 407 | + // https://localhost:9444/v1/tags |
| 408 | + it('tags', () => { |
| 409 | + // Create a tag for us to test with |
| 410 | + cy.visit('default/Assembly%20Election%202017.sqlite') |
| 411 | + cy.get('[data-cy="tagscnt"]').should('contain', '0') |
| 412 | + cy.get('[data-cy="commitslnk"]').click() |
| 413 | + cy.get('[data-cy="createtagrelbtn"]').click() |
| 414 | + cy.get('[data-cy="nameinput"]').type('{selectall}{backspace}').type('Some tag name').should('have.value', 'Some tag name') |
| 415 | + cy.get('[data-cy="desctext"]').type('{selectall}{backspace}').type('Some tag description').should('have.value', 'Some tag description') |
| 416 | + cy.get('[data-cy="previewtab"]').click() |
| 417 | + cy.get('[data-cy="previewdiv"]').should('contain', 'Some tag description') |
| 418 | + cy.get('[data-cy="createbtn"]').click() |
| 419 | + cy.visit('default/Assembly%20Election%202017.sqlite') |
| 420 | + cy.get('[data-cy="tagscnt"]').should('contain', '1') |
| 421 | + |
| 422 | + // Test the tag details using the API |
| 423 | + cy.request({ |
| 424 | + method: 'POST', |
| 425 | + url: 'https://localhost:9444/v1/tags', |
| 426 | + form: true, |
| 427 | + body: { |
| 428 | + apikey: '2MXwA5jGZkIQ3UNEcKsuDNSPMlx', |
| 429 | + dbowner: 'default', |
| 430 | + dbname: 'Assembly Election 2017.sqlite' |
| 431 | + }, |
| 432 | + }).then( |
| 433 | + (response) => { |
| 434 | + expect(response.status).to.eq(200) |
| 435 | + |
| 436 | + let jsonBody = JSON.parse(response.body) |
| 437 | + expect(jsonBody).to.have.property('Some tag name') |
| 438 | + expect(jsonBody['Some tag name']).to.include.keys(['commit', 'date']) |
| 439 | + expect(jsonBody['Some tag name']).to.have.property('description', 'Some tag description') |
| 440 | + expect(jsonBody['Some tag name']).to.have.property('email', '[email protected]') |
| 441 | + expect(jsonBody['Some tag name']).to.have.property('name', 'Default system user') |
| 442 | + } |
| 443 | + ) |
| 444 | + }) |
| 445 | + |
319 | 446 | // Webpage
|
320 | 447 | // Equivalent curl command:
|
321 | 448 | // curl -k -F apikey="2MXwA5jGZkIQ3UNEcKsuDNSPMlx" \
|
|
0 commit comments