2024-02-28 06:41:34 +01:00
|
|
|
/// <reference types="cypress" />
|
2024-03-01 22:00:59 +01:00
|
|
|
import { uuid } from '../../src/lib/crypto';
|
2024-02-28 06:41:34 +01:00
|
|
|
|
2024-03-01 22:00:59 +01:00
|
|
|
Cypress.Commands.add('getDataTest', (value: string) => {
|
|
|
|
return cy.get(`[data-test=${value}]`);
|
2024-02-28 06:41:34 +01:00
|
|
|
});
|
2024-03-01 02:40:49 +01:00
|
|
|
|
|
|
|
Cypress.Commands.add('login', (username: string, password: string) => {
|
2024-03-01 22:00:59 +01:00
|
|
|
cy.session([username, password], () => {
|
|
|
|
cy.request({
|
|
|
|
method: 'POST',
|
|
|
|
url: '/api/auth/login',
|
|
|
|
body: {
|
|
|
|
username,
|
|
|
|
password,
|
2024-03-01 02:40:49 +01:00
|
|
|
},
|
2024-03-01 22:00:59 +01:00
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
Cypress.env('authorization', `bearer ${response.body.token}`);
|
|
|
|
window.localStorage.setItem('umami.auth', JSON.stringify(response.body.token));
|
|
|
|
})
|
|
|
|
.its('status')
|
|
|
|
.should('eq', 200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
Cypress.Commands.add('addWebsite', (name: string, domain: string) => {
|
|
|
|
cy.request({
|
|
|
|
method: 'POST',
|
|
|
|
url: '/api/websites',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
Authorization: Cypress.env('authorization'),
|
|
|
|
},
|
|
|
|
body: {
|
|
|
|
id: uuid(),
|
|
|
|
createdBy: '41e2b680-648e-4b09-bcd7-3e2b10c06264',
|
|
|
|
name: name,
|
|
|
|
domain: domain,
|
|
|
|
},
|
|
|
|
}).then(response => {
|
|
|
|
expect(response.status).to.eq(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
Cypress.Commands.add('deleteWebsite', (websiteId: string) => {
|
|
|
|
cy.request({
|
|
|
|
method: 'DELETE',
|
|
|
|
url: `/api/websites/${websiteId}`,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
Authorization: Cypress.env('authorization'),
|
2024-03-01 02:40:49 +01:00
|
|
|
},
|
2024-03-01 22:00:59 +01:00
|
|
|
}).then(response => {
|
|
|
|
expect(response.status).to.eq(200);
|
|
|
|
});
|
2024-03-01 02:40:49 +01:00
|
|
|
});
|