DigitalConsumer.ISS/playwright-tests/impl/api/ApiResponseInterceptUtil.ts
chase-safelite 5d3ab0ef59
Added playwright tests into repo (#923)
* Initial import of playwright tests

* Pipeline changes for automated tests

* Modified pipeline for testing

* Attempt #2

* Attempt #3

* Added missing paren

* Removed debug stuff from pipeline

* Changes from playwright repo

* Changed pipeline for debugging

* Fix for ServiceLocationPage playwright locators

* Change pipeline to run with TEST APIs

* Moved more of Siraj's changes to this repo

* Changed where updating env occurs

* Changed location of env update again

* Escaped double quotes

* Added visible report in Azure

* Moved changes into main pipeline

* Made it so dotenv only runs config in local
2025-02-14 09:54:11 -05:00

47 lines
No EOL
1.8 KiB
TypeScript

import { IPartsOrQuestionsResponse } from "@business-logic/types/DigitalApi";
import { ITestData } from "@business-logic/types/ITestData";
import { expect, Response } from "@playwright/test";
export default class ApiResponseInterceptUtil {
readonly testData: Partial<ITestData>;
constructor(testData: Partial<ITestData>) {
this.testData = testData;
// Bind callback functions to the class instance so 'this' is usable within a callback
this.handleInterceptResponse = this.handleInterceptResponse.bind(this);
this.handlePartsOrQuestionsResponse = this.handlePartsOrQuestionsResponse.bind(this);
}
async handleInterceptResponse(response: Response) {
if (!response.url().includes('safelite.io')) {
return;
}
const urlPath = response.url().split('safelite.io')[1]; // get api path
switch(urlPath) {
case '/parts/api/v1/parts/parts-or-questions':
await this.handlePartsOrQuestionsResponse(response);
break;
default:
break;
}
if (response.url().endsWith('/parts/parts-or-questions') && response.status() === 200) {
}
}
async handlePartsOrQuestionsResponse(response: Response) {
if (this.testData.hasOemEndorsement) {
const partsRes = (await response.json()) as IPartsOrQuestionsResponse;
for ( const partOrQuestion of partsRes.partsOrQuestions) {
for (const part of partOrQuestion.parts) {
expect.soft(part.partNumber.endsWith('OEM'),
`handlePartsOrQuestionsResponse>> OEM endorsement was expected, but "${part.partType}" with part number "${part.partNumber}" is not OEM.`
).toEqual(true);
}
}
}
}
}