Skip to content

Commit 246cc3b

Browse files
karur4nclaude
andcommitted
feat: add region validation for Terminal Cloud API
- Add validation to require region parameter when initializing TerminalCloudAPI - Throw clear error message when region is not specified - Add tests to verify region validation behavior 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent f8743c2 commit 246cc3b

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

src/__mocks__/base.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
import Client from "../client";
21-
import Config, { EnvironmentEnum } from "../config";
21+
import Config, { EnvironmentEnum, RegionEnum } from "../config";
2222
import {
2323
AmountsReq,
2424
MessageCategoryType,
@@ -38,6 +38,7 @@ import {
3838
export const createClient = (apiKey = process.env.ADYEN_API_KEY): Client => {
3939
const config: Config = new Config();
4040
config.environment = EnvironmentEnum.TEST;
41+
config.region = RegionEnum.EU;
4142
config.terminalApiCloudEndpoint = Client.TERMINAL_API_ENDPOINT_TEST;
4243
config.terminalApiLocalEndpoint = "https://mocked_local_endpoint.com";
4344
config.marketPayEndpoint = Client.MARKETPAY_ENDPOINT_TEST;

src/__tests__/terminalCloudAPI.spec.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { syncRefund, syncRes, syncResEventNotification, syncResEventNotification
55
import Client from "../client";
66
import TerminalCloudAPI from "../services/terminalCloudAPI";
77
import { terminal } from "../typings";
8-
import { EnvironmentEnum } from "../config";
8+
import { EnvironmentEnum, RegionEnum } from "../config";
99
import HttpClientException from "../httpClient/httpClientException";
1010

1111
let client: Client;
@@ -27,6 +27,26 @@ afterEach((): void => {
2727
});
2828

2929
describe("Terminal Cloud API", (): void => {
30+
test("should throw error when region is not specified", (): void => {
31+
const clientWithoutRegion = new Client({
32+
apiKey: "YOUR_API_KEY",
33+
environment: EnvironmentEnum.TEST
34+
});
35+
36+
expect(() => new TerminalCloudAPI(clientWithoutRegion))
37+
.toThrow("Region is required for Terminal API");
38+
});
39+
40+
test("should initialize successfully with region", (): void => {
41+
const clientWithRegion = new Client({
42+
apiKey: "YOUR_API_KEY",
43+
environment: EnvironmentEnum.TEST,
44+
region: RegionEnum.EU
45+
});
46+
47+
expect(() => new TerminalCloudAPI(clientWithRegion)).not.toThrow();
48+
});
49+
3050
test("should make an async payment request", async (): Promise<void> => {
3151
scope.post("/async").reply(200, asyncRes);
3252

@@ -141,7 +161,7 @@ describe("Terminal Cloud API", (): void => {
141161

142162
const terminalApiHost = "https://terminal-api-test.adyen.com";
143163

144-
const client = new Client({ apiKey: "YOUR_API_KEY", environment: EnvironmentEnum.TEST });
164+
const client = new Client({ apiKey: "YOUR_API_KEY", environment: EnvironmentEnum.TEST, region: RegionEnum.EU });
145165
const terminalCloudAPI = new TerminalCloudAPI(client);
146166

147167
const terminalAPIPaymentRequest = createTerminalAPIPaymentRequest();
@@ -168,7 +188,7 @@ describe("Terminal Cloud API", (): void => {
168188
test("sync should validate 308 location header", async (): Promise<void> => {
169189
const terminalApiHost = "https://terminal-api-test.adyen.com";
170190

171-
const client = new Client({ apiKey: "YOUR_API_KEY", environment: EnvironmentEnum.TEST });
191+
const client = new Client({ apiKey: "YOUR_API_KEY", environment: EnvironmentEnum.TEST, region: RegionEnum.EU });
172192

173193
const terminalCloudAPI = new TerminalCloudAPI(client);
174194

@@ -203,10 +223,9 @@ describe("Terminal Cloud API", (): void => {
203223
});
204224

205225
test("async should skip 308 redirect", async (): Promise<void> => {
206-
207226
const terminalApiHost = "https://terminal-api-test.adyen.com";
208227

209-
const client = new Client({ apiKey: "YOUR_API_KEY", environment: EnvironmentEnum.TEST, enable308Redirect: false });
228+
const client = new Client({ apiKey: "YOUR_API_KEY", environment: EnvironmentEnum.TEST, region: RegionEnum.EU, enable308Redirect: false });
210229
const terminalCloudAPI = new TerminalCloudAPI(client);
211230

212231
const terminalAPIPaymentRequest = createTerminalAPIPaymentRequest();

src/services/terminalCloudAPI.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class TerminalCloudAPI extends Service {
3232

3333
public constructor(client: Client) {
3434
super(client);
35+
36+
if (!client.config.region) {
37+
throw new Error("Region is required for Terminal API");
38+
}
39+
3540
this.apiKeyRequired = true;
3641
this.terminalApiAsync = new Async(this);
3742
this.terminalApiSync = new Sync(this);

0 commit comments

Comments
 (0)