Add e2e tests
This commit is contained in:
1
tests/e2e/fixtures/catapi.json
Normal file
1
tests/e2e/fixtures/catapi.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "message": "FAKE Cat API" }
|
||||
7
tests/e2e/integration/app.starter.spec.js
Normal file
7
tests/e2e/integration/app.starter.spec.js
Normal file
@@ -0,0 +1,7 @@
|
||||
describe('Visit home', () => {
|
||||
it('Have a page title with "Postwoman"', () => {
|
||||
cy.visit('/')
|
||||
.get('title')
|
||||
.should('contain','Postwoman')
|
||||
})
|
||||
})
|
||||
57
tests/e2e/integration/feature.url-queries.spec.js
Normal file
57
tests/e2e/integration/feature.url-queries.spec.js
Normal file
@@ -0,0 +1,57 @@
|
||||
describe('Methods', () => {
|
||||
const methods = [ 'POST', 'HEAD', 'POST', 'PUT', 'DELETE','OPTIONS', 'PATCH']
|
||||
methods.forEach(method => {
|
||||
it(`Change the default method GET to ${method} with url query`, () => {
|
||||
cy.visit(`/?method=${method}`)
|
||||
.get('#method').contains(method)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('Url and path', () => {
|
||||
it('Change default url with query and reset default path to empty string and make a request to cat api', () => {
|
||||
cy.seedAndVisit('catapi', '/?url=https://api.thecatapi.com&path=')
|
||||
.get('#url').then(el => expect(el.val() === 'https://api.thecatapi.com').to.equal(true))
|
||||
.get("#path").then(el => expect(el.val() === '').to.equal(true))
|
||||
.get('#response-details-wrapper').should($wrapper => {
|
||||
expect($wrapper).to.contain('FAKE Cat API')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('Authentication', () => {
|
||||
it(`Change default auth 'None' to 'Basic' and set httpUser and httpPassword with url query`, () => {
|
||||
cy.visit(`?&auth=Basic&httpUser=foo&httpPassword=bar`, { retryOnStatusCodeFailure: true })
|
||||
.get('#authentication').contains('Authentication').click()
|
||||
.then(() => {
|
||||
cy.get('input[name="http_basic_user"]', { timeout: 500 })
|
||||
.invoke('val')
|
||||
.then(user => {
|
||||
expect(user === 'foo').to.equal(true)
|
||||
cy.log('Success! user === foo')
|
||||
})
|
||||
|
||||
cy.get('input[name="http_basic_passwd"]')
|
||||
.invoke('val')
|
||||
.then(user => {
|
||||
expect(user === 'bar').to.equal(true)
|
||||
cy.log('Success! password === bar')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
const base64Tkn = encodeURI(btoa('{"alg":"HS256", "typ": "JWT"}'))
|
||||
|
||||
it(`Change default auth 'None' to 'Bearer token' and set bearerToken with url query`, () => {
|
||||
cy.visit(`/?auth=Bearer Token&bearerToken=${base64Tkn}`, { retryOnStatusCodeFailure: true })
|
||||
.get('#authentication').contains('Authentication').click()
|
||||
.then(() => {
|
||||
cy.get('input[name="bearer_token"]', { timeout: 500 })
|
||||
.invoke('val')
|
||||
.then(tkn => {
|
||||
expect(tkn === base64Tkn).to.equal(true)
|
||||
cy.log(`Success! input[name="bearer_token"] === ${base64Tkn}`)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
16
tests/e2e/support/commands.js
Normal file
16
tests/e2e/support/commands.js
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Creates cy.seedAndVisit() function
|
||||
* This function will go to some path and wait for some fake response from 'src/tests/fixtures/*.json'
|
||||
* @param { String } seedData The name of json at 'src/tests/fixtures/
|
||||
* @param { String } path The path or query parameters to go -ex. '/?path=/api/users'
|
||||
* @param { String } method The fake request method
|
||||
*/
|
||||
Cypress.Commands.add('seedAndVisit', (seedData, path = '/', method = 'GET') => {
|
||||
cy.server()
|
||||
.route(method, 'https://api.thecatapi.com/', `fixture:${seedData}`).as(
|
||||
'load'
|
||||
)
|
||||
cy.visit(path)
|
||||
.get('#send').click()
|
||||
.wait('@load')
|
||||
})
|
||||
1
tests/e2e/support/index.js
Normal file
1
tests/e2e/support/index.js
Normal file
@@ -0,0 +1 @@
|
||||
import './commands'
|
||||
Reference in New Issue
Block a user