Skip to content

Commit 6f49282

Browse files
committed
test(config-resolver): getResolvedSigningRegion.spec.ts
1 parent 679b306 commit 6f49282

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { getResolvedSigningRegion } from "./getResolvedSigningRegion";
2+
import { isFipsRegion } from "./isFipsRegion";
3+
4+
jest.mock("./isFipsRegion");
5+
6+
describe(getResolvedSigningRegion.name, () => {
7+
const mockRegion = "mockRegion";
8+
const mockSigningRegion = "mockSigningRegion";
9+
const mockHostname = "mockHostname";
10+
const mockRegionRegex = "mockRegionRegex";
11+
12+
const mockOptions = {
13+
hostname: mockHostname,
14+
regionRegex: mockRegionRegex,
15+
};
16+
17+
beforeEach(() => {
18+
(isFipsRegion as jest.Mock).mockReturnValue(false);
19+
});
20+
21+
afterEach(() => {
22+
jest.clearAllMocks();
23+
});
24+
25+
it("returns signingRegion if passed in options", () => {
26+
expect(getResolvedSigningRegion(mockRegion, { ...mockOptions, signingRegion: mockSigningRegion })).toEqual(
27+
mockSigningRegion
28+
);
29+
expect(isFipsRegion).not.toHaveBeenCalled();
30+
});
31+
32+
describe("returns undefined if signingRegion is not present and", () => {
33+
it("region is not FIPS", () => {
34+
expect(getResolvedSigningRegion(mockRegion, mockOptions)).not.toBeDefined();
35+
expect(isFipsRegion).toHaveBeenCalledTimes(1);
36+
expect(isFipsRegion).toHaveBeenCalledWith(mockRegion);
37+
});
38+
39+
it("regionRegex does not return a match in hostname", () => {
40+
(isFipsRegion as jest.Mock).mockReturnValueOnce(true);
41+
const matchSpy = jest.spyOn(String.prototype, "match").mockReturnValueOnce(null);
42+
43+
expect(getResolvedSigningRegion(mockRegion, mockOptions)).not.toBeDefined();
44+
expect(matchSpy).toHaveBeenCalledTimes(1);
45+
expect(matchSpy).toHaveBeenCalledWith(mockRegionRegex);
46+
expect(isFipsRegion).toHaveBeenCalledTimes(1);
47+
expect(isFipsRegion).toHaveBeenCalledWith(mockRegion);
48+
});
49+
});
50+
51+
it("returns region from hostname is signingRegion is not present", () => {
52+
(isFipsRegion as jest.Mock).mockReturnValueOnce(true);
53+
const matchSpy = jest.spyOn(String.prototype, "match").mockReturnValueOnce([mockSigningRegion]);
54+
55+
expect(getResolvedSigningRegion(mockRegion, mockOptions)).toEqual(mockSigningRegion);
56+
expect(matchSpy).toHaveBeenCalledTimes(1);
57+
expect(matchSpy).toHaveBeenCalledWith(mockRegionRegex);
58+
expect(isFipsRegion).toHaveBeenCalledTimes(1);
59+
expect(isFipsRegion).toHaveBeenCalledWith(mockRegion);
60+
});
61+
});

0 commit comments

Comments
 (0)