144 lines
3.2 KiB
TypeScript
144 lines
3.2 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 city search API
|
|
*/
|
|
mockCitySearch: () => {
|
|
const mockCities = [
|
|
{ code: 'SVO', name: 'Moscow Sheremetyevo', country: 'Russia' },
|
|
{ code: 'LED', name: 'Saint Petersburg Pulkovo', country: 'Russia' },
|
|
{ code: 'AER', name: 'Sochi', country: 'Russia' },
|
|
{ code: 'DME', name: 'Moscow Domodedovo', country: 'Russia' },
|
|
{ code: 'VKO', name: 'Moscow Vnukovo', country: 'Russia' },
|
|
]
|
|
|
|
cy.intercept('GET', '**/api/cities/search**', {
|
|
statusCode: 200,
|
|
body: mockCities,
|
|
}).as('citySearch')
|
|
},
|
|
|
|
/**
|
|
* Mock flight search response
|
|
*/
|
|
mockFlightSearch: () => {
|
|
const mockFlights = [
|
|
{
|
|
id: '1',
|
|
flightNumber: 'SU100',
|
|
status: 'ON_TIME',
|
|
operator: 'Aeroflot',
|
|
aircraft: 'Airbus A320',
|
|
departure: {
|
|
airport: 'SVO',
|
|
city: 'Moscow',
|
|
scheduled: '10:00',
|
|
actual: '10:05',
|
|
terminal: 'B',
|
|
gate: '5A',
|
|
},
|
|
arrival: {
|
|
airport: 'LED',
|
|
city: 'Saint Petersburg',
|
|
scheduled: '12:00',
|
|
actual: '11:55',
|
|
terminal: '1',
|
|
gate: '10',
|
|
},
|
|
boarding: {
|
|
time: '09:30',
|
|
gate: '5A',
|
|
},
|
|
codesharing: [],
|
|
},
|
|
{
|
|
id: '2',
|
|
flightNumber: 'SU101',
|
|
status: 'DELAYED',
|
|
operator: 'Aeroflot',
|
|
aircraft: 'Boeing 737',
|
|
departure: {
|
|
airport: 'SVO',
|
|
city: 'Moscow',
|
|
scheduled: '11:00',
|
|
actual: '11:15',
|
|
terminal: 'A',
|
|
gate: '2B',
|
|
},
|
|
arrival: {
|
|
airport: 'LED',
|
|
city: 'Saint Petersburg',
|
|
scheduled: '13:00',
|
|
terminal: '2',
|
|
gate: '15',
|
|
},
|
|
codesharing: [],
|
|
},
|
|
{
|
|
id: '3',
|
|
flightNumber: 'SU102',
|
|
status: 'BOARDING',
|
|
operator: 'Aeroflot',
|
|
aircraft: 'Airbus A321',
|
|
departure: {
|
|
airport: 'SVO',
|
|
city: 'Moscow',
|
|
scheduled: '12:30',
|
|
terminal: 'C',
|
|
gate: '8C',
|
|
},
|
|
arrival: {
|
|
airport: 'LED',
|
|
city: 'Saint Petersburg',
|
|
scheduled: '14:30',
|
|
terminal: '1',
|
|
gate: '20',
|
|
},
|
|
boarding: {
|
|
time: '12:00',
|
|
gate: '8C',
|
|
},
|
|
codesharing: [],
|
|
},
|
|
]
|
|
|
|
cy.intercept('GET', '**/api/flights**', {
|
|
statusCode: 200,
|
|
body: {
|
|
flights: mockFlights,
|
|
},
|
|
}).as('flightSearch')
|
|
},
|
|
}
|