Skip to content

Commit

Permalink
test: add tests for environments configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
aripalo committed Nov 21, 2024
1 parent b793e7f commit 71ba781
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 3 deletions.
37 changes: 37 additions & 0 deletions src/configurations/__snapshots__/environments.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

87 changes: 87 additions & 0 deletions src/configurations/environments.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
6 changes: 3 additions & 3 deletions src/configurations/environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ export const labelToCategory: Record<EnvironmentLabel, EnvironmentCategory> = {
[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
Expand Down

0 comments on commit 71ba781

Please sign in to comment.