Merge branch 'develop' into PW-7518

This commit is contained in:
jillingk
2023-01-19 11:41:47 +01:00
committed by GitHub
2 changed files with 43 additions and 4 deletions

View File

@@ -222,15 +222,27 @@ describe("Checkout", (): void => {
expect(paymentsResponse.pspReference).toBeTruthy();
});
test("should return correct Exception", async (): Promise<void> => {
test("Should properly handle error responses from API", async (): Promise<void> => {
try {
scope.post("/payments")
.reply(401);
.reply(422, {
"status": 422,
"errorCode": "200",
"message": "Field 'countryCode' is not valid.",
"errorType": "validation",
"pspReference": "DMB552CV6JHKGK82",
});
const paymentsRequest: checkout.PaymentRequest = createPaymentsCheckoutRequest();
await checkoutService.payments(paymentsRequest);
} catch (e) {
expect(e instanceof HttpClientException).toBeTruthy();
fail("No exception was thrown");
} catch (error) {
expect(error instanceof HttpClientException).toBeTruthy();
if(error instanceof HttpClientException && error.responseBody) {
expect(JSON.parse(error.responseBody).errorType).toBe("validation");
} else {
fail("Error did not contain the expected data");
}
}
});

View File

@@ -5,6 +5,7 @@ import { Management } from "../services";
import { management } from "../typings";
import * as requests from "../__mocks__/management/requests";
import * as responses from "../__mocks__/management/responses";
import HttpClientException from "../httpClient/httpClientException";
let client: Client;
let managementService: Management;
@@ -34,6 +35,32 @@ afterEach(() => {
describe("Management", (): void => {
describe("Me", (): void => {
test("Should properly handle error responses from API", async (): Promise<void> => {
scope.post("/me/allowedOrigins")
.reply(422, {
"type": "https://docs.adyen.com/errors/not-found",
"title": "Entity was not found",
"status": 422,
"detail": "The origin id is invalid or does not exist.",
"requestId": "KQZ5LXK2VMPRMC82",
"errorCode": "30_112",
});
try {
const createAllowedOriginRequest : management.CreateAllowedOriginRequest = {
domain: "test.com",
};
await managementService.Me.createAllowedOrigin(createAllowedOriginRequest);
fail("No exception was thrown");
} catch (error) {
expect(error instanceof HttpClientException).toBeTruthy();
if(error instanceof HttpClientException && error.responseBody) {
expect(JSON.parse(error.responseBody).requestId).toBe("KQZ5LXK2VMPRMC82");
} else {
fail("Error did not contain the expected data");
}
}
});
test("Should get API credential details based on the API Key used in the request", async (): Promise<void> => {
scope.get("/me")
.reply(200, {