Skip to content

Commit e4a985a

Browse files
committed
Test async error
1 parent 3e3609d commit e4a985a

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

src/__mocks__/terminalApi/async.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,25 @@
1818
*/
1919

2020
export const asyncRes = "ok";
21+
22+
export const asyncErrorRes = {
23+
SaleToPOIRequest: {
24+
EventNotification: {
25+
EventToNotify: "Reject",
26+
EventDetails: "message=Did+not+receive+a+response+from+the+POI.",
27+
RejectedMessage: "ewoi...0KfQo=",
28+
TimeStamp: "2020-03-31T10:28:39.515Z"
29+
},
30+
MessageHeader: {
31+
DeviceID: "666568147",
32+
MessageCategory: "Event",
33+
MessageClass: "Event",
34+
MessageType: "Notification",
35+
POIID: "P400Plus-123456789",
36+
ProtocolVersion: "3.0",
37+
SaleID: "saleid-4c32759faaa7",
38+
ServiceID: "31122609"
39+
}
40+
}
41+
};
42+

src/__tests__/terminalCloudAPI.spec.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import nock from "nock";
22
import { createClient, createTerminalAPIPaymentRequest, createTerminalAPIRefundRequest } from "../__mocks__/base";
3-
import { asyncRes } from "../__mocks__/terminalApi/async";
3+
import { asyncRes, asyncErrorRes } from "../__mocks__/terminalApi/async";
44
import { syncRefund, syncRes, syncResEventNotification, syncResEventNotificationWithAdditionalAttributes, syncResEventNotificationWithUnknownEnum } from "../__mocks__/terminalApi/sync";
55
import Client from "../client";
66
import TerminalCloudAPI from "../services/terminalCloudAPI";
@@ -30,11 +30,27 @@ describe("Terminal Cloud API", (): void => {
3030

3131
const terminalAPIPaymentRequest = createTerminalAPIPaymentRequest();
3232

33-
const requestResponse: string = await terminalCloudAPI.async(terminalAPIPaymentRequest);
33+
const requestResponse = await terminalCloudAPI.async(terminalAPIPaymentRequest);
3434

35+
expect(typeof requestResponse).toBe("string");
3536
expect(requestResponse).toEqual("ok");
3637
});
3738

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+
3854
test("should make a sync payment request", async (): Promise<void> => {
3955
scope.post("/sync").reply(200, syncRes);
4056

@@ -453,4 +469,3 @@ export const syncTerminalPaymentResponse = {
453469
}
454470
}
455471
};
456-

0 commit comments

Comments
 (0)