diff --git a/src/configurations/__snapshots__/environments.test.ts.snap b/src/configurations/__snapshots__/environments.test.ts.snap new file mode 100644 index 0000000..a23bdca --- /dev/null +++ b/src/configurations/__snapshots__/environments.test.ts.snap @@ -0,0 +1,37 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`EnvironmentCategory 1`] = ` +Object { + "DEVELOPMENT": "development", + "FEATURE": "feature", + "MOCK": "mock", + "STABLE": "stable", + "VERIFICATION": "verification", +} +`; + +exports[`EnvironmentLabel 1`] = ` +Object { + "DEVELOPMENT": "development", + "FEATURE": "feature/[/a-zA-z0-9-]+", + "MOCK": "mock[0-9]", + "PREPRODUCTION": "preproduction", + "PRODUCTION": "production", + "QA": "qa[0-9]", + "STAGING": "staging", + "TEST": "test", +} +`; + +exports[`labelToCategory 1`] = ` +Object { + "development": "development", + "feature/[/a-zA-z0-9-]+": "feature", + "mock[0-9]": "mock", + "preproduction": "verification", + "production": "stable", + "qa[0-9]": "verification", + "staging": "stable", + "test": "verification", +} +`; diff --git a/src/configurations/environments.test.ts b/src/configurations/environments.test.ts new file mode 100644 index 0000000..5cf95d2 --- /dev/null +++ b/src/configurations/environments.test.ts @@ -0,0 +1,87 @@ +import { + EnvironmentCategory, + EnvironmentLabel, + labelToCategory, + ENV_REGEXP_MOCK, + ENV_REGEXP_FEATURE, + ENV_REGEXP_QA, + getLabelByName, + getCategoryByLabel, +} from "./environments"; + +test("EnvironmentCategory", () => { + expect(EnvironmentCategory).toMatchSnapshot(); +}); + +test("EnvironmentLabel", () => { + expect(EnvironmentLabel).toMatchSnapshot(); +}); + +test("labelToCategory", () => { + expect(labelToCategory).toMatchSnapshot(); +}); + +describe("ENV_REGEXP_*", () => { + test("ENV_REGEXP_MOCK", () => { + expect(ENV_REGEXP_MOCK.test("mock1")).toBe(true); + expect(ENV_REGEXP_MOCK.test("mock2")).toBe(true); + expect(ENV_REGEXP_MOCK.test("mock3")).toBe(true); + expect(ENV_REGEXP_MOCK.test("mock4")).toBe(true); + expect(ENV_REGEXP_MOCK.test("mock5")).toBe(true); + }); + + test("ENV_REGEXP_FEATURE", () => { + expect(ENV_REGEXP_FEATURE.test("feature/foo")).toBe(true); + expect(ENV_REGEXP_FEATURE.test("feature/ticket-123/foobar")).toBe(true); + }); + + test("ENV_REGEXP_QA", () => { + expect(ENV_REGEXP_QA.test("qa1")).toBe(true); + expect(ENV_REGEXP_QA.test("qa2")).toBe(true); + expect(ENV_REGEXP_QA.test("qa3")).toBe(true); + expect(ENV_REGEXP_QA.test("qa4")).toBe(true); + expect(ENV_REGEXP_QA.test("qa5")).toBe(true); + }); +}); + +describe("getLabelByName", () => { + test.each([ + { name: "mock1", expected: EnvironmentLabel.MOCK }, + { name: "feature/foo", expected: EnvironmentLabel.FEATURE }, + { name: "qa1", expected: EnvironmentLabel.QA }, + { name: "development", expected: EnvironmentLabel.DEVELOPMENT }, + { name: "test", expected: EnvironmentLabel.TEST }, + { name: "staging", expected: EnvironmentLabel.STAGING }, + { name: "preproduction", expected: EnvironmentLabel.PREPRODUCTION }, + { name: "production", expected: EnvironmentLabel.PRODUCTION }, + ])("$name", ({ name, expected }) => { + expect(getLabelByName(name)).toBe(expected); + }); +}); + +describe("getCategoryByLabel", () => { + test.each([ + { label: EnvironmentLabel.MOCK, expected: EnvironmentCategory.MOCK }, + { + label: EnvironmentLabel.DEVELOPMENT, + expected: EnvironmentCategory.DEVELOPMENT, + }, + { label: EnvironmentLabel.FEATURE, expected: EnvironmentCategory.FEATURE }, + { + label: EnvironmentLabel.TEST, + expected: EnvironmentCategory.VERIFICATION, + }, + { label: EnvironmentLabel.STAGING, expected: EnvironmentCategory.STABLE }, + { label: EnvironmentLabel.QA, expected: EnvironmentCategory.VERIFICATION }, + { + label: EnvironmentLabel.PREPRODUCTION, + expected: EnvironmentCategory.VERIFICATION, + }, + { + label: EnvironmentLabel.PRODUCTION, + expected: EnvironmentCategory.STABLE, + }, + ])("$label", ({ label, expected }) => { + expect(getCategoryByLabel(label)).toBe(expected); + }); +}); diff --git a/src/configurations/environments.ts b/src/configurations/environments.ts index 4e8cae5..002c611 100644 --- a/src/configurations/environments.ts +++ b/src/configurations/environments.ts @@ -59,9 +59,9 @@ export const labelToCategory: Record = { [EnvironmentLabel.PRODUCTION]: EnvironmentCategory.STABLE, }; -const ENV_REGEXP_MOCK = new EnvRegExp(EnvironmentLabel.MOCK); -const ENV_REGEXP_FEATURE = new EnvRegExp(EnvironmentLabel.FEATURE); -const ENV_REGEXP_QA = new EnvRegExp(EnvironmentLabel.QA); +export const ENV_REGEXP_MOCK = new EnvRegExp(EnvironmentLabel.MOCK); +export const ENV_REGEXP_FEATURE = new EnvRegExp(EnvironmentLabel.FEATURE); +export const ENV_REGEXP_QA = new EnvRegExp(EnvironmentLabel.QA); /** * TODO document