Changeset View
Changeset View
Standalone View
Standalone View
cypress/support/index.js
Show All 13 Lines | |||||
}); | }); | ||||
Cypress.Commands.add('xhrShouldBeCalled', (alias, timesCalled) => { | Cypress.Commands.add('xhrShouldBeCalled', (alias, timesCalled) => { | ||||
const testRoutes = cy.state('routes'); | const testRoutes = cy.state('routes'); | ||||
const aliasRoute = Cypress._.find(testRoutes, {alias}); | const aliasRoute = Cypress._.find(testRoutes, {alias}); | ||||
expect(Object.keys(aliasRoute.requests || {})).to.have.length(timesCalled); | expect(Object.keys(aliasRoute.requests || {})).to.have.length(timesCalled); | ||||
}); | }); | ||||
Cypress.Commands.add('adminLogin', () => { | function loginUser(username, password) { | ||||
const url = '/admin/login/'; | const url = '/admin/login/'; | ||||
return cy.request({ | return cy.request({ | ||||
url: url, | url: url, | ||||
method: 'GET' | method: 'GET' | ||||
}).then(() => { | }).then(() => { | ||||
cy.getCookie('sessionid').should('not.exist'); | cy.getCookie('sessionid').should('not.exist'); | ||||
cy.getCookie('csrftoken').its('value').then((token) => { | cy.getCookie('csrftoken').its('value').then((token) => { | ||||
cy.request({ | cy.request({ | ||||
url: url, | url: url, | ||||
method: 'POST', | method: 'POST', | ||||
form: true, | form: true, | ||||
followRedirect: false, | followRedirect: false, | ||||
body: { | body: { | ||||
username: 'admin', | username: username, | ||||
password: 'admin', | password: password, | ||||
csrfmiddlewaretoken: token | csrfmiddlewaretoken: token | ||||
} | } | ||||
}).then(() => { | }).then(() => { | ||||
cy.getCookie('sessionid').should('exist'); | cy.getCookie('sessionid').should('exist'); | ||||
return cy.getCookie('csrftoken').its('value'); | return cy.getCookie('csrftoken').its('value'); | ||||
}); | }); | ||||
}); | }); | ||||
}); | }); | ||||
} | |||||
Cypress.Commands.add('adminLogin', () => { | |||||
return loginUser('admin', 'admin'); | |||||
}); | |||||
Cypress.Commands.add('userLogin', () => { | |||||
return loginUser('user', 'user'); | |||||
}); | }); | ||||
before(function() { | before(function() { | ||||
this.unarchivedRepo = { | this.unarchivedRepo = { | ||||
url: 'https://github.com/SoftwareHeritage/swh-web', | url: 'https://github.com/SoftwareHeritage/swh-web', | ||||
type: 'git', | type: 'git', | ||||
revision: '7bf1b2f489f16253527807baead7957ca9e8adde', | revision: '7bf1b2f489f16253527807baead7957ca9e8adde', | ||||
snapshot: 'd9829223095de4bb529790de8ba4e4813e38672d', | snapshot: 'd9829223095de4bb529790de8ba4e4813e38672d', | ||||
▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines |