|
| 1 | +import { afterEach, describe, expect, test as it, vi } from "vitest"; |
| 2 | + |
| 3 | +import { getArrayForCommaSeparatedString } from "../utils/getArrayForCommaSeparatedString"; |
| 4 | +import { NODE_AUTH_SCHEME_PREFERENCE_OPTIONS } from "./NODE_AUTH_SCHEME_PREFERENCE_OPTIONS"; |
| 5 | + |
| 6 | +vi.mock("../utils/getArrayForCommaSeparatedString"); |
| 7 | + |
| 8 | +describe("NODE_AUTH_SCHEME_PREFERENCE_OPTIONS", () => { |
| 9 | + const mockInput = "a,b,c"; |
| 10 | + const mockOutput = ["a", "b", "c"]; |
| 11 | + |
| 12 | + vi.mocked(getArrayForCommaSeparatedString).mockReturnValue(mockOutput); |
| 13 | + |
| 14 | + afterEach(() => { |
| 15 | + vi.clearAllMocks(); |
| 16 | + }); |
| 17 | + |
| 18 | + const test = (func: Function, key: string) => { |
| 19 | + it("returns undefined if no value is provided", () => { |
| 20 | + expect(func({})).toEqual(undefined); |
| 21 | + expect(getArrayForCommaSeparatedString).not.toBeCalled(); |
| 22 | + }); |
| 23 | + |
| 24 | + it("returns list if value is defined", () => { |
| 25 | + expect(func({ [key]: mockInput })).toEqual(mockOutput); |
| 26 | + expect(getArrayForCommaSeparatedString).toHaveBeenCalledTimes(1); |
| 27 | + expect(getArrayForCommaSeparatedString).toBeCalledWith(mockInput); |
| 28 | + }); |
| 29 | + }; |
| 30 | + |
| 31 | + describe("environmentVariableSelector", () => { |
| 32 | + const { environmentVariableSelector } = NODE_AUTH_SCHEME_PREFERENCE_OPTIONS; |
| 33 | + test(environmentVariableSelector, "AWS_AUTH_SCHEME_PREFERENCE"); |
| 34 | + }); |
| 35 | + |
| 36 | + describe("configFileSelector", () => { |
| 37 | + const { configFileSelector } = NODE_AUTH_SCHEME_PREFERENCE_OPTIONS; |
| 38 | + test(configFileSelector, "auth_scheme_preference"); |
| 39 | + }); |
| 40 | + |
| 41 | + it("returns false for default", () => { |
| 42 | + const { default: defaultValue } = NODE_AUTH_SCHEME_PREFERENCE_OPTIONS; |
| 43 | + expect(defaultValue).toEqual([]); |
| 44 | + }); |
| 45 | +}); |
0 commit comments