qe-fe-automation
Version:
FE test automation framework using cypress
68 lines (59 loc) • 2.15 kB
text/typescript
import { HttpRequest } from '@support-base/http_request';
import { AUTH_TOKEN } from 'cypress/support/commands';
const tripUrl = '/api/admin/trips/timeline?tripUuid';
function fetchTripData() {
return cy.task('getDataFromCache', 'rentalCarTripItemUuid').then((tripUuid) => {
if (!AUTH_TOKEN) {
throw new Error('No Auth Token');
}
return cy.request({
method: HttpRequest.Get,
url: `${tripUrl}=${tripUuid}&tripItemMapIncluded=true`,
headers: {
Authorization: AUTH_TOKEN,
Accept: 'application/json'
},
retryOnStatusCodeFailure: true
});
});
}
export function getTripData() {
fetchTripData().then((response) => {
cy.log(JSON.stringify(response.body[0].tripItemsMap));
const tripItemsMap = response.body[0].tripItemsMap;
const firstItemKey = Object.keys(tripItemsMap)[0];
expect(tripItemsMap[firstItemKey].car.automatic).to.be.true;
});
}
export function getBookingData(directBillName: string) {
fetchTripData().then((response) => {
const tripItemsMap = response.body[0].tripItemsMap;
const firstItemKey = Object.keys(tripItemsMap)[0];
const bookingData = tripItemsMap[firstItemKey].bookingData;
expect(bookingData.creditCardType).to.equal('DIRECT_BILL');
expect(bookingData.creditCardName).to.equal(directBillName);
expect(bookingData.companyCreditCard).to.be.true;
});
}
export function getExistingBookingDetails() {
fetchTripData().then((response) => {
const tripItemsMap = response.body[0].tripItemsMap;
let hasHotel = false;
let hasCar = false;
let tripFeeIsValid = false;
for (const key in tripItemsMap) {
if (tripItemsMap[key].type === 'HOTEL') {
hasHotel = true;
}
if (tripItemsMap[key].type === 'CAR') {
hasCar = true;
}
if (tripItemsMap[key].tripFee === 5) {
tripFeeIsValid = true;
}
}
expect(hasHotel, 'Hotel is present in the current booking').to.be.true;
expect(hasCar, 'Car is present in the current booking').to.be.true;
expect(tripFeeIsValid, 'Trip fee is $5 present in the current trip').to.be.true;
});
}