|
| 1 | +import { Endpoint } from "@aws-sdk/types"; |
| 2 | + |
| 3 | +import { resolveCustomEndpointsConfig } from "./CustomEndpointsConfig"; |
| 4 | + |
| 5 | +describe("CustomEndpointsConfig", () => { |
| 6 | + const urlParser = jest.fn(); |
| 7 | + |
| 8 | + const input = { urlParser }; |
| 9 | + |
| 10 | + afterEach(() => { |
| 11 | + jest.clearAllMocks(); |
| 12 | + }); |
| 13 | + |
| 14 | + describe("endpoint", () => { |
| 15 | + const mockEndpoint: Endpoint = { protocol: "protocol", hostname: "hostname", path: "path" }; |
| 16 | + |
| 17 | + it("returns output of urlParser if endpoint is of type string", async () => { |
| 18 | + const endpoint = "endpoint"; |
| 19 | + urlParser.mockReturnValueOnce(mockEndpoint); |
| 20 | + const { endpoint: endpointProvider, isCustomEndpoint } = resolveCustomEndpointsConfig({ ...input, endpoint }); |
| 21 | + expect(isCustomEndpoint).toBe(true); |
| 22 | + const endpointOutput = await endpointProvider(); |
| 23 | + expect(endpointOutput).toStrictEqual(mockEndpoint); |
| 24 | + expect(urlParser).toHaveBeenCalledTimes(1); |
| 25 | + expect(urlParser).toHaveBeenCalledWith(endpoint); |
| 26 | + }); |
| 27 | + |
| 28 | + it("returns promisified endpoint if it's of type object", async () => { |
| 29 | + const endpoint = mockEndpoint; |
| 30 | + const { endpoint: endpointProvider, isCustomEndpoint } = resolveCustomEndpointsConfig({ ...input, endpoint }); |
| 31 | + expect(isCustomEndpoint).toBe(true); |
| 32 | + const endpointOutput = await endpointProvider(); |
| 33 | + expect(endpointOutput).toStrictEqual(endpoint); |
| 34 | + expect(urlParser).not.toHaveBeenCalled(); |
| 35 | + }); |
| 36 | + |
| 37 | + it("returns endpoint if it's already Provider<Endpoint>", async () => { |
| 38 | + const endpoint = () => Promise.resolve(mockEndpoint); |
| 39 | + const { endpoint: endpointProvider, isCustomEndpoint } = resolveCustomEndpointsConfig({ ...input, endpoint }); |
| 40 | + expect(isCustomEndpoint).toBe(true); |
| 41 | + const endpointOutput = await endpointProvider(); |
| 42 | + expect(endpointOutput).toStrictEqual(mockEndpoint); |
| 43 | + expect(urlParser).not.toHaveBeenCalled(); |
| 44 | + }); |
| 45 | + }); |
| 46 | + |
| 47 | + describe("tls", () => { |
| 48 | + const endpoint = "endpoint"; |
| 49 | + |
| 50 | + beforeEach(() => { |
| 51 | + urlParser.mockReturnValueOnce({ protocol: "protocol", hostname: "hostname", path: "path" }); |
| 52 | + }); |
| 53 | + |
| 54 | + [true, false].forEach((tls) => { |
| 55 | + it(`returns input.tls when it's ${tls}`, () => { |
| 56 | + expect(resolveCustomEndpointsConfig({ ...input, endpoint, tls }).tls).toStrictEqual(tls); |
| 57 | + }); |
| 58 | + }); |
| 59 | + |
| 60 | + it("returns true is input.tls is undefined", () => { |
| 61 | + expect(resolveCustomEndpointsConfig({ ...input, endpoint }).tls).toStrictEqual(true); |
| 62 | + }); |
| 63 | + }); |
| 64 | +}); |
0 commit comments