mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
add custom command for reusable login via API
This commit is contained in:
parent
1418d2e8fb
commit
9890898191
@ -31,13 +31,16 @@ export default defineConfig({
|
||||
excludeSpecPattern: "*.js",
|
||||
baseUrl: 'http://localhost:3000',
|
||||
chromeWebSecurity: false,
|
||||
supportFile: false,
|
||||
supportFile: 'cypress/support/index.ts',
|
||||
viewportHeight: 720,
|
||||
viewportWidth: 1280,
|
||||
retries: {
|
||||
runMode: 2,
|
||||
openMode: 0
|
||||
},
|
||||
env: {
|
||||
backendURL: 'http://localhost:4000',
|
||||
},
|
||||
setupNodeEvents
|
||||
}
|
||||
})
|
||||
|
||||
26
e2e-tests/cypress/tests/cypress/support/e2e.ts
Normal file
26
e2e-tests/cypress/tests/cypress/support/e2e.ts
Normal file
@ -0,0 +1,26 @@
|
||||
Cypress.Commands.add('login', (email, password) => {
|
||||
Cypress.LocalStorage.clear
|
||||
|
||||
cy.request({
|
||||
method: 'POST',
|
||||
url: Cypress.env('backendURL'),
|
||||
body: {
|
||||
"operationName": null,
|
||||
"variables": {
|
||||
"email": email,
|
||||
"password": password
|
||||
},
|
||||
"query": "query ($email: String!, $password: String!, $publisherId: Int) {\n login(email: $email, password: $password, publisherId: $publisherId) {\n email\n firstName\n lastName\n language\n klickTipp {\n newsletterState\n __typename\n }\n hasElopage\n publisherId\n isAdmin\n creation\n __typename\n }\n}\n"
|
||||
}
|
||||
})
|
||||
.then((response) => {
|
||||
let vuexToken = {
|
||||
token : JSON.parse(JSON.stringify(response.headers))['token'],
|
||||
// TODO: how to compute the token time from the token im response?
|
||||
tokenTime : 1663224487
|
||||
};
|
||||
|
||||
cy.visit('/');
|
||||
window.localStorage.setItem('vuex', JSON.stringify(vuexToken));
|
||||
})
|
||||
})
|
||||
11
e2e-tests/cypress/tests/cypress/support/index.ts
Normal file
11
e2e-tests/cypress/tests/cypress/support/index.ts
Normal file
@ -0,0 +1,11 @@
|
||||
/// <reference types="cypress" />
|
||||
|
||||
import './e2e';
|
||||
|
||||
declare global {
|
||||
namespace Cypress {
|
||||
interface Chainable<Subject> {
|
||||
login(email: string, password: string): Chainable<any>
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3,8 +3,8 @@
|
||||
"target": "es2016",
|
||||
"lib": ["es6", "dom"],
|
||||
"baseUrl": "../node_modules",
|
||||
"types": ["cypress", "node"],
|
||||
"strict": true
|
||||
"types": ["cypress", "node"],
|
||||
"strict": true
|
||||
},
|
||||
"include": ["**/*.ts"]
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user