-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path.codex-cypress-commands.js
More file actions
79 lines (71 loc) · 2.31 KB
/
Copy path.codex-cypress-commands.js
File metadata and controls
79 lines (71 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
Cypress.Commands.add('login', (email, password) => {
cy.session(
[email, password],
() => {
const apiUrl = Cypress.env('apiUrl')
cy.request({
method: 'POST',
url: `${apiUrl}/api/auth/login`,
body: { email, password },
failOnStatusCode: true,
}).then((response) => {
const { accessToken, refreshToken } = response.body
window.localStorage.setItem('hw_access_token', accessToken)
window.localStorage.setItem('hw_refresh_token', refreshToken)
})
},
{
validate() {
cy.window().its('localStorage').invoke('getItem', 'hw_access_token').should('exist')
},
}
)
})
Cypress.Commands.add('loginAsAdmin', () => {
cy.login('admin@evinsta.com', 'password123')
})
Cypress.Commands.add('loginAsManager', () => {
cy.login('sarah@evinsta.com', 'password123')
})
Cypress.Commands.add('loginAsEmployee', () => {
cy.login('tom@evinsta.com', 'password123')
})
Cypress.Commands.add('getByTestId', (testId) => {
return cy.get(`[data-testid="${testId}"]`)
})
Cypress.Commands.add('getOrCreateTestLookups', (token) => {
const apiUrl = Cypress.env('apiUrl')
const headers = { Authorization: `Bearer ${token}` }
cy.request({ url: `${apiUrl}/api/categories?entityType=hardware`, headers }).then((res) => {
if (res.body.length > 0) {
Cypress.env('testCategoryId', res.body[0]._id)
} else {
cy.request({
method: 'POST',
url: `${apiUrl}/api/categories`,
headers,
body: { name: 'E2E Test Category', entityType: 'hardware' },
}).then((createRes) => {
Cypress.env('testCategoryId', createRes.body._id)
})
}
})
cy.request({ url: `${apiUrl}/api/manufacturers`, headers }).then((res) => {
if (res.body.length > 0) {
Cypress.env('testManufacturerId', res.body[0]._id)
} else {
cy.request({
method: 'POST',
url: `${apiUrl}/api/manufacturers`,
headers,
body: { name: 'E2E Test Manufacturer' },
}).then((createRes) => {
Cypress.env('testManufacturerId', createRes.body._id)
})
}
})
cy.request({ url: `${apiUrl}/api/statuses`, headers }).then((res) => {
const deployable = res.body.find((s) => s.type === 'deployable')
Cypress.env('testStatusId', deployable?._id || res.body[0]._id)
})
})