|
1 | 1 | import nock from "nock"; |
2 | 2 | import { createClient, createTerminalAPIPaymentRequest, createTerminalAPIRefundRequest } from "../__mocks__/base"; |
3 | | -import { asyncRes } from "../__mocks__/terminalApi/async"; |
| 3 | +import { asyncRes, asyncErrorRes } from "../__mocks__/terminalApi/async"; |
4 | 4 | import { syncRefund, syncRes, syncResEventNotification, syncResEventNotificationWithAdditionalAttributes, syncResEventNotificationWithUnknownEnum } from "../__mocks__/terminalApi/sync"; |
5 | 5 | import Client from "../client"; |
6 | 6 | import TerminalCloudAPI from "../services/terminalCloudAPI"; |
@@ -30,11 +30,27 @@ describe("Terminal Cloud API", (): void => { |
30 | 30 |
|
31 | 31 | const terminalAPIPaymentRequest = createTerminalAPIPaymentRequest(); |
32 | 32 |
|
33 | | - const requestResponse: string = await terminalCloudAPI.async(terminalAPIPaymentRequest); |
| 33 | + const requestResponse = await terminalCloudAPI.async(terminalAPIPaymentRequest); |
34 | 34 |
|
| 35 | + expect(typeof requestResponse).toBe("string"); |
35 | 36 | expect(requestResponse).toEqual("ok"); |
36 | 37 | }); |
37 | 38 |
|
| 39 | + test("should get an error after async payment request", async (): Promise<void> => { |
| 40 | + scope.post("/async").reply(200, asyncErrorRes); |
| 41 | + |
| 42 | + const terminalAPIPaymentRequest = createTerminalAPIPaymentRequest(); |
| 43 | + |
| 44 | + const requestResponse = await terminalCloudAPI.async(terminalAPIPaymentRequest); |
| 45 | + |
| 46 | + if (typeof requestResponse === "object") { |
| 47 | + expect(requestResponse.SaleToPOIRequest?.EventNotification).toBeDefined(); |
| 48 | + expect(requestResponse.SaleToPOIRequest?.EventNotification?.EventToNotify).toBe("Reject"); |
| 49 | + } else { |
| 50 | + throw new Error("Expected structured response, but got raw string"); |
| 51 | + } |
| 52 | + }); |
| 53 | + |
38 | 54 | test("should make a sync payment request", async (): Promise<void> => { |
39 | 55 | scope.post("/sync").reply(200, syncRes); |
40 | 56 |
|
@@ -453,4 +469,3 @@ export const syncTerminalPaymentResponse = { |
453 | 469 | } |
454 | 470 | } |
455 | 471 | }; |
456 | | - |
|
0 commit comments