]>
Commit | Line | Data |
---|---|---|
e306af50 TL |
1 | declare global { |
2 | namespace Cypress { | |
3 | interface Chainable<Subject> { | |
4 | login(): void; | |
5 | text(): Chainable<string>; | |
6 | } | |
7 | } | |
8 | } | |
9 | ||
f67539c2 | 10 | import { Permissions } from '~/app/shared/models/permissions'; |
e306af50 TL |
11 | |
12 | let auth: any; | |
13 | ||
14 | const fillAuth = () => { | |
15 | window.localStorage.setItem('dashboard_username', auth.username); | |
e306af50 TL |
16 | window.localStorage.setItem('dashboard_permissions', auth.permissions); |
17 | window.localStorage.setItem('user_pwd_expiration_date', auth.pwdExpirationDate); | |
18 | window.localStorage.setItem('user_pwd_update_required', auth.pwdUpdateRequired); | |
19 | window.localStorage.setItem('sso', auth.sso); | |
20 | }; | |
21 | ||
22 | Cypress.Commands.add('login', () => { | |
23 | const username = Cypress.env('LOGIN_USER') || 'admin'; | |
24 | const password = Cypress.env('LOGIN_PWD') || 'admin'; | |
25 | ||
26 | if (auth === undefined) { | |
27 | cy.request({ | |
28 | method: 'POST', | |
29 | url: 'api/auth', | |
f67539c2 | 30 | headers: { Accept: 'application/vnd.ceph.api.v1.0+json' }, |
e306af50 TL |
31 | body: { username: username, password: password } |
32 | }).then((resp) => { | |
33 | auth = resp.body; | |
34 | auth.permissions = JSON.stringify(new Permissions(auth.permissions)); | |
35 | auth.pwdExpirationDate = String(auth.pwdExpirationDate); | |
36 | auth.pwdUpdateRequired = String(auth.pwdUpdateRequired); | |
37 | auth.sso = String(auth.sso); | |
38 | fillAuth(); | |
39 | }); | |
40 | } else { | |
41 | fillAuth(); | |
42 | } | |
43 | }); | |
44 | ||
45 | Cypress.Commands.add('text', { prevSubject: true }, (subject) => { | |
46 | return subject.text(); | |
47 | }); |