Files
flights_web_raw/e2e/cypress/support/helpers/api-helpers.ts
T
gnezim 9356945d93 Task 10: Create test helper files and base test templates
- Create helpers directory structure
- Add api-helpers.ts with authentication and API mocking functions
- Add ui-helpers.ts with common UI interaction utilities
- Add data-helpers.ts with test data generators
- Create base.spec.ts as reusable test template
- Update support/index.ts to import and expose helper modules globally
2026-04-05 19:19:49 +03:00

55 lines
1.1 KiB
TypeScript

/**
* API helper functions for e2e tests
*/
export const apiHelpers = {
/**
* Get auth token (mock for now, will be real API later)
*/
getAuthToken: () => {
return cy.window().then(win => win.localStorage.getItem('auth_token'))
},
/**
* Set auth token in localStorage
*/
setAuthToken: (token: string) => {
cy.window().then(win => {
win.localStorage.setItem('auth_token', token)
})
},
/**
* Make API call via cy.request
*/
apiCall: (method: string, endpoint: string, body?: any) => {
return cy.request({
method,
url: `http://localhost:3000/api${endpoint}`,
body,
failOnStatusCode: false,
})
},
/**
* Mock flight search response
*/
mockFlightSearch: () => {
cy.intercept('GET', '**/api/flights/**', {
statusCode: 200,
body: {
flights: [
{
id: '1',
number: 'SU123',
departureTime: '10:00',
arrivalTime: '12:00',
from: 'SVO',
to: 'LED',
},
],
},
}).as('flightSearch')
},
}