tests(fix): update start-server-and-test, update e2e tests, change build test command at ci
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
describe('Visit home', () => {
|
||||
it('Have a page title with "Postwoman"', () => {
|
||||
cy.visit('/')
|
||||
.get('title')
|
||||
cy.visit('/', { retryOnStatusCodeFailure: true })
|
||||
.get('title')
|
||||
.should('contain','Postwoman')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,57 +1,34 @@
|
||||
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').should('have.value', 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`, () => {
|
||||
it(`Change default auth user and pass with url`, () => {
|
||||
cy.visit(`?&auth=Basic Auth&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')
|
||||
})
|
||||
.get('input[name="http_basic_user"]', { timeout: 500 })
|
||||
.invoke('val')
|
||||
.then((user) => {
|
||||
expect(user === 'foo').to.equal(true)
|
||||
})
|
||||
|
||||
cy.get('input[name="http_basic_passwd"]')
|
||||
.invoke('val')
|
||||
.then((user) => {
|
||||
expect(user === 'bar').to.equal(true)
|
||||
cy.log('Success! password === bar')
|
||||
})
|
||||
})
|
||||
.get('input[name="http_basic_passwd"]')
|
||||
.invoke('val')
|
||||
.then((pass) => {
|
||||
expect(pass === 'bar').to.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
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}`)
|
||||
})
|
||||
})
|
||||
})
|
||||
it('Enable user and pass at url with toggler', () => {
|
||||
cy.visit('/', { retryOnStatusCodeFailure: true })
|
||||
.get('#auth')
|
||||
.select('Basic Auth')
|
||||
.get('input[name="http_basic_user"]', { timeout: 500 })
|
||||
.type('foo')
|
||||
.get('input[name="http_basic_passwd"]', { timeout: 500 })
|
||||
.type('bar')
|
||||
.url()
|
||||
.should('not.contain', 'foo')
|
||||
.should('not.contain', 'bar')
|
||||
.get('.toggle')
|
||||
.click()
|
||||
.url()
|
||||
.should('contain', 'foo')
|
||||
.should('contain', 'bar')
|
||||
})
|
||||
})
|
||||
|
||||
20
tests/e2e/integration/proxy.spec.js
Normal file
20
tests/e2e/integration/proxy.spec.js
Normal file
@@ -0,0 +1,20 @@
|
||||
describe('Proxy disabled - local request', () => {
|
||||
it('Change default url with query and make a request to local 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('Proxy enabled - external request', () => {
|
||||
it('Enable the proxy and make a request to the real cat api', () => {
|
||||
cy.enableProxy('/?url=https://api.thecatapi.com&path=')
|
||||
.get('#send').click()
|
||||
.get('#response-details-wrapper').should($wrapper => {
|
||||
expect($wrapper).to.contain('Cat API')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -7,10 +7,23 @@
|
||||
*/
|
||||
Cypress.Commands.add('seedAndVisit', (seedData, path = '/', method = 'GET') => {
|
||||
cy.server()
|
||||
.route(method, 'https://api.thecatapi.com/', `fixture:${seedData}`).as(
|
||||
'load'
|
||||
)
|
||||
.route(method, 'https://api.thecatapi.com/', `fixture:${seedData}`).as('load')
|
||||
|
||||
cy.visit(path)
|
||||
.get('#send').click()
|
||||
.wait('@load')
|
||||
.wait('@load')
|
||||
})
|
||||
|
||||
/**
|
||||
* Creates cy.enableProxy() function
|
||||
* This function will enable the proxy and navigate back to a given path
|
||||
* @param { String } goBackPath The page go back
|
||||
*/
|
||||
Cypress.Commands.add('enableProxy', (goBackPath) => {
|
||||
cy.visit('/settings')
|
||||
.get('#proxy')
|
||||
.find('.toggle')
|
||||
.click( { force: true } )
|
||||
.should('have.class', 'on')
|
||||
.visit(goBackPath)
|
||||
})
|
||||
Reference in New Issue
Block a user