import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
import {
getCurrentEnvironment,
getFeatureFlags,
} from "../../src/config/environments.js";
describe("environments", () => {
const originalEnv = process.env;
beforeEach(() => {
vi.resetModules();
process.env = { ...originalEnv };
});
afterEach(() => {
process.env = originalEnv;
});
describe("getCurrentEnvironment", () => {
it("should return TST by default", () => {
delete process.env.BIRST_ENV;
expect(getCurrentEnvironment()).toBe("TST");
});
it("should return TST when BIRST_ENV is set to TST", () => {
process.env.BIRST_ENV = "TST";
expect(getCurrentEnvironment()).toBe("TST");
});
it("should return PRD when BIRST_ENV is set to PRD", () => {
process.env.BIRST_ENV = "PRD";
expect(getCurrentEnvironment()).toBe("PRD");
});
it("should return TRN when BIRST_ENV is set to TRN", () => {
process.env.BIRST_ENV = "TRN";
expect(getCurrentEnvironment()).toBe("TRN");
});
it("should handle lowercase environment values", () => {
process.env.BIRST_ENV = "prd";
expect(getCurrentEnvironment()).toBe("PRD");
});
it("should return TST for invalid environment values", () => {
process.env.BIRST_ENV = "INVALID";
expect(getCurrentEnvironment()).toBe("TST");
});
});
describe("getFeatureFlags", () => {
it("should return false for all flags by default", () => {
delete process.env.BIRST_ENABLE_GENAI;
delete process.env.BIRST_ENABLE_ICW;
const flags = getFeatureFlags();
expect(flags.enableGenAI).toBe(false);
expect(flags.enableICW).toBe(false);
});
it("should enable GenAI when BIRST_ENABLE_GENAI is true", () => {
process.env.BIRST_ENABLE_GENAI = "true";
const flags = getFeatureFlags();
expect(flags.enableGenAI).toBe(true);
});
it("should enable ICW when BIRST_ENABLE_ICW is true", () => {
process.env.BIRST_ENABLE_ICW = "true";
const flags = getFeatureFlags();
expect(flags.enableICW).toBe(true);
});
it("should not enable flags for non-true values", () => {
process.env.BIRST_ENABLE_GENAI = "false";
process.env.BIRST_ENABLE_ICW = "1";
const flags = getFeatureFlags();
expect(flags.enableGenAI).toBe(false);
expect(flags.enableICW).toBe(false);
});
it("should enable both flags when both are set to true", () => {
process.env.BIRST_ENABLE_GENAI = "true";
process.env.BIRST_ENABLE_ICW = "true";
const flags = getFeatureFlags();
expect(flags.enableGenAI).toBe(true);
expect(flags.enableICW).toBe(true);
});
});
});