Skip to content

Commit 5462379

Browse files
committed
Use SaleID instead of POIID, add test to validate Location url
1 parent 876f5eb commit 5462379

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/__tests__/terminalCloudAPI.spec.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,12 @@ describe("Terminal Cloud API", (): void => {
128128

129129
const terminalAPIPaymentRequest = createTerminalAPIPaymentRequest();
130130
// custom value to trigger mock 308 response
131-
terminalAPIPaymentRequest.SaleToPOIRequest.MessageHeader.POIID = "response-with-redirect";
131+
terminalAPIPaymentRequest.SaleToPOIRequest.MessageHeader.SaleID = "response-with-redirect";
132132

133133
// Mock first request: returns a 308 redirect with Location header
134134
nock(terminalApiHost)
135135
.post("/async", (body) => {
136-
return body?.SaleToPOIRequest?.MessageHeader?.POIID === "response-with-redirect";
136+
return body?.SaleToPOIRequest?.MessageHeader?.SaleID === "response-with-redirect";
137137
})
138138
.reply(308, "", { Location: `${terminalApiHost}/async?redirect=false` });
139139

@@ -147,22 +147,22 @@ describe("Terminal Cloud API", (): void => {
147147
expect(terminalAPIResponse).toEqual("ok");
148148
});
149149

150-
test("sync should handle 308", async (): Promise<void> => {
150+
test("sync should validate 308 location header", async (): Promise<void> => {
151151
const terminalApiHost = "https://terminal-api-test.adyen.com";
152152

153153
const client = new Client({ apiKey: "YOUR_API_KEY", environment: "TEST" });
154154
const terminalCloudAPI = new TerminalCloudAPI(client);
155155

156156
const terminalAPIPaymentRequest = createTerminalAPIPaymentRequest();
157157
// custom value to trigger mock 308 response
158-
terminalAPIPaymentRequest.SaleToPOIRequest.MessageHeader.POIID = "response-with-redirect";
158+
terminalAPIPaymentRequest.SaleToPOIRequest.MessageHeader.SaleID = "response-with-redirect";
159159

160-
// Mock first request: returns a 308 redirect with Location header
160+
// Mock first request: returns a 308 redirect with invalid Location header
161161
nock(terminalApiHost)
162162
.post("/sync", (body) => {
163-
return body?.SaleToPOIRequest?.MessageHeader?.POIID === "response-with-redirect";
163+
return body?.SaleToPOIRequest?.MessageHeader?.SaleID === "response-with-redirect";
164164
})
165-
.reply(308, "", { Location: `${terminalApiHost}/sync?redirect=false` });
165+
.reply(308, "", { Location: "https://example.org/sync?redirect=false" });
166166

167167
// Mock follow-up request: returns successful response
168168
nock(terminalApiHost)
@@ -174,12 +174,14 @@ describe("Terminal Cloud API", (): void => {
174174
},
175175
});
176176

177-
const terminalAPIResponse: terminal.TerminalApiResponse = await terminalCloudAPI.sync(terminalAPIPaymentRequest);
177+
try {
178+
await terminalCloudAPI.sync(terminalAPIPaymentRequest);
179+
fail("No exception was thrown");
180+
} catch (e) {
181+
expect(e).toBeInstanceOf(Error);
182+
}
178183

179-
expect(terminalAPIResponse.SaleToPOIResponse?.PaymentResponse).toBeDefined();
180-
expect(terminalAPIResponse.SaleToPOIResponse?.MessageHeader).toBeDefined();
181-
expect(terminalAPIResponse.SaleToPOIResponse?.MessageHeader?.SaleID).toBe("001-308");
182-
});
184+
});
183185

184186
});
185187

0 commit comments

Comments
 (0)