|
1 |
| -import { normalizeConfigFile } from "./normalizeConfigFile"; |
| 1 | +import { getProfileData } from "./getProfileData"; |
2 | 2 |
|
3 |
| -describe(normalizeConfigFile.name, () => { |
| 3 | +describe(getProfileData.name, () => { |
4 | 4 | it("returns empty for no data", () => {
|
5 |
| - expect(normalizeConfigFile({})).toStrictEqual({}); |
| 5 | + expect(getProfileData({})).toStrictEqual({}); |
6 | 6 | });
|
7 | 7 |
|
8 | 8 | it("returns default profile if present", () => {
|
9 | 9 | const mockInput = { default: { key: "value" } };
|
10 |
| - expect(normalizeConfigFile(mockInput)).toStrictEqual(mockInput); |
| 10 | + expect(getProfileData(mockInput)).toStrictEqual(mockInput); |
11 | 11 | });
|
12 | 12 |
|
13 | 13 | it("skips profiles without prefix profile", () => {
|
14 | 14 | const mockInput = { test: { key: "value" } };
|
15 |
| - expect(normalizeConfigFile(mockInput)).toStrictEqual({}); |
| 15 | + expect(getProfileData(mockInput)).toStrictEqual({}); |
| 16 | + }); |
| 17 | + |
| 18 | + it("skips profiles with different prefix", () => { |
| 19 | + const mockInput = { "not-profile test": { key: "value" } }; |
| 20 | + expect(getProfileData(mockInput)).toStrictEqual({}); |
16 | 21 | });
|
17 | 22 |
|
18 | 23 | describe("normalizes profile names", () => {
|
19 |
| - const getProfileData = (profileName: string) => |
| 24 | + const getMockProfileData = (profileName: string) => |
20 | 25 | [1, 2, 3]
|
21 | 26 | .map((num) => [`key_${profileName}_${num}`, `value_${profileName}_${num}`])
|
22 | 27 | .reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});
|
23 | 28 |
|
24 | 29 | const getMockOutput = (profileNames: string[]) =>
|
25 |
| - profileNames.reduce((acc, profileName) => ({ ...acc, [profileName]: getProfileData(profileName) }), {}); |
| 30 | + profileNames.reduce((acc, profileName) => ({ ...acc, [profileName]: getMockProfileData(profileName) }), {}); |
26 | 31 |
|
27 | 32 | const getMockInput = (mockOutput: { [key: string]: { [key: string]: string } }) =>
|
28 | 33 | Object.entries(mockOutput).reduce((acc, [key, value]) => ({ ...acc, [`profile ${key}`]: value }), {});
|
29 | 34 |
|
30 | 35 | it("single profile", () => {
|
31 | 36 | const mockOutput = getMockOutput(["one"]);
|
32 | 37 | const mockInput = getMockInput(mockOutput);
|
33 |
| - expect(normalizeConfigFile(mockInput)).toStrictEqual(mockOutput); |
| 38 | + expect(getProfileData(mockInput)).toStrictEqual(mockOutput); |
34 | 39 | });
|
35 | 40 |
|
36 | 41 | it("two profiles", () => {
|
37 | 42 | const mockOutput = getMockOutput(["one", "two"]);
|
38 | 43 | const mockInput = getMockInput(mockOutput);
|
39 |
| - expect(normalizeConfigFile(mockInput)).toStrictEqual(mockOutput); |
| 44 | + expect(getProfileData(mockInput)).toStrictEqual(mockOutput); |
40 | 45 | });
|
41 | 46 |
|
42 | 47 | it("three profiles", () => {
|
43 | 48 | const mockOutput = getMockOutput(["one", "two", "three"]);
|
44 | 49 | const mockInput = getMockInput(mockOutput);
|
45 |
| - expect(normalizeConfigFile(mockInput)).toStrictEqual(mockOutput); |
| 50 | + expect(getProfileData(mockInput)).toStrictEqual(mockOutput); |
46 | 51 | });
|
47 | 52 |
|
48 | 53 | it("with default", () => {
|
49 | 54 | const defaultInput = { default: { key: "value" } };
|
50 | 55 | const mockOutput = getMockOutput(["one"]);
|
51 | 56 | const mockInput = getMockInput(mockOutput);
|
52 |
| - expect(normalizeConfigFile({ ...defaultInput, ...mockInput })).toStrictEqual({ ...defaultInput, ...mockOutput }); |
| 57 | + expect(getProfileData({ ...defaultInput, ...mockInput })).toStrictEqual({ ...defaultInput, ...mockOutput }); |
53 | 58 | });
|
54 | 59 |
|
55 | 60 | it("with profileName without prefix", () => {
|
56 | 61 | const profileWithPrefix = { test: { key: "value" } };
|
57 | 62 | const mockOutput = getMockOutput(["one"]);
|
58 | 63 | const mockInput = getMockInput(mockOutput);
|
59 |
| - expect(normalizeConfigFile({ ...profileWithPrefix, ...mockInput })).toStrictEqual(mockOutput); |
| 64 | + expect(getProfileData({ ...profileWithPrefix, ...mockInput })).toStrictEqual(mockOutput); |
60 | 65 | });
|
61 | 66 | });
|
62 | 67 | });
|
0 commit comments