|
| 1 | +import { |
| 2 | + isCloudEnvironment, |
| 3 | + getAppEnvironment, |
| 4 | + isPreviewEnvironment, |
| 5 | + isProductionEnvironment, |
| 6 | + isDevelopmentEnvironment, |
| 7 | +} from "../cloud-environment" |
| 8 | + |
| 9 | +describe("cloud-environment", () => { |
| 10 | + const originalEnv = process.env |
| 11 | + |
| 12 | + beforeEach(() => { |
| 13 | + // Reset process.env before each test |
| 14 | + vi.resetModules() |
| 15 | + process.env = { ...originalEnv } |
| 16 | + }) |
| 17 | + |
| 18 | + afterAll(() => { |
| 19 | + // Restore original process.env after all tests |
| 20 | + process.env = originalEnv |
| 21 | + }) |
| 22 | + |
| 23 | + describe("isCloudEnvironment", () => { |
| 24 | + it("should return true when ROO_CODE_IPC_SOCKET_PATH is set", () => { |
| 25 | + process.env.ROO_CODE_IPC_SOCKET_PATH = "/tmp/test.sock" |
| 26 | + expect(isCloudEnvironment()).toBe(true) |
| 27 | + }) |
| 28 | + |
| 29 | + it("should return false when ROO_CODE_IPC_SOCKET_PATH is not set", () => { |
| 30 | + delete process.env.ROO_CODE_IPC_SOCKET_PATH |
| 31 | + expect(isCloudEnvironment()).toBe(false) |
| 32 | + }) |
| 33 | + |
| 34 | + it("should return false when ROO_CODE_IPC_SOCKET_PATH is undefined", () => { |
| 35 | + process.env.ROO_CODE_IPC_SOCKET_PATH = undefined as any |
| 36 | + expect(isCloudEnvironment()).toBe(false) |
| 37 | + }) |
| 38 | + }) |
| 39 | + |
| 40 | + describe("getAppEnvironment", () => { |
| 41 | + it('should return "development" when ROO_CODE_APP_ENV is development', () => { |
| 42 | + process.env.ROO_CODE_APP_ENV = "development" |
| 43 | + expect(getAppEnvironment()).toBe("development") |
| 44 | + }) |
| 45 | + |
| 46 | + it('should return "preview" when ROO_CODE_APP_ENV is preview', () => { |
| 47 | + process.env.ROO_CODE_APP_ENV = "preview" |
| 48 | + expect(getAppEnvironment()).toBe("preview") |
| 49 | + }) |
| 50 | + |
| 51 | + it('should return "production" when ROO_CODE_APP_ENV is production', () => { |
| 52 | + process.env.ROO_CODE_APP_ENV = "production" |
| 53 | + expect(getAppEnvironment()).toBe("production") |
| 54 | + }) |
| 55 | + |
| 56 | + it("should return undefined when ROO_CODE_APP_ENV is not set", () => { |
| 57 | + delete process.env.ROO_CODE_APP_ENV |
| 58 | + expect(getAppEnvironment()).toBeUndefined() |
| 59 | + }) |
| 60 | + |
| 61 | + it("should return undefined when ROO_CODE_APP_ENV has invalid value", () => { |
| 62 | + process.env.ROO_CODE_APP_ENV = "invalid" |
| 63 | + expect(getAppEnvironment()).toBeUndefined() |
| 64 | + }) |
| 65 | + }) |
| 66 | + |
| 67 | + describe("isPreviewEnvironment", () => { |
| 68 | + it('should return true when ROO_CODE_APP_ENV is "preview"', () => { |
| 69 | + process.env.ROO_CODE_APP_ENV = "preview" |
| 70 | + expect(isPreviewEnvironment()).toBe(true) |
| 71 | + }) |
| 72 | + |
| 73 | + it('should return false when ROO_CODE_APP_ENV is "production"', () => { |
| 74 | + process.env.ROO_CODE_APP_ENV = "production" |
| 75 | + expect(isPreviewEnvironment()).toBe(false) |
| 76 | + }) |
| 77 | + |
| 78 | + it('should return false when ROO_CODE_APP_ENV is "development"', () => { |
| 79 | + process.env.ROO_CODE_APP_ENV = "development" |
| 80 | + expect(isPreviewEnvironment()).toBe(false) |
| 81 | + }) |
| 82 | + |
| 83 | + it("should return false when ROO_CODE_APP_ENV is not set", () => { |
| 84 | + delete process.env.ROO_CODE_APP_ENV |
| 85 | + expect(isPreviewEnvironment()).toBe(false) |
| 86 | + }) |
| 87 | + }) |
| 88 | + |
| 89 | + describe("isProductionEnvironment", () => { |
| 90 | + it('should return true when ROO_CODE_APP_ENV is "production"', () => { |
| 91 | + process.env.ROO_CODE_APP_ENV = "production" |
| 92 | + expect(isProductionEnvironment()).toBe(true) |
| 93 | + }) |
| 94 | + |
| 95 | + it('should return false when ROO_CODE_APP_ENV is "preview"', () => { |
| 96 | + process.env.ROO_CODE_APP_ENV = "preview" |
| 97 | + expect(isProductionEnvironment()).toBe(false) |
| 98 | + }) |
| 99 | + |
| 100 | + it("should return false when ROO_CODE_APP_ENV is not set", () => { |
| 101 | + delete process.env.ROO_CODE_APP_ENV |
| 102 | + expect(isProductionEnvironment()).toBe(false) |
| 103 | + }) |
| 104 | + }) |
| 105 | + |
| 106 | + describe("isDevelopmentEnvironment", () => { |
| 107 | + it('should return true when ROO_CODE_APP_ENV is "development"', () => { |
| 108 | + process.env.ROO_CODE_APP_ENV = "development" |
| 109 | + expect(isDevelopmentEnvironment()).toBe(true) |
| 110 | + }) |
| 111 | + |
| 112 | + it('should return false when ROO_CODE_APP_ENV is "production"', () => { |
| 113 | + process.env.ROO_CODE_APP_ENV = "production" |
| 114 | + expect(isDevelopmentEnvironment()).toBe(false) |
| 115 | + }) |
| 116 | + |
| 117 | + it("should return false when ROO_CODE_APP_ENV is not set", () => { |
| 118 | + delete process.env.ROO_CODE_APP_ENV |
| 119 | + expect(isDevelopmentEnvironment()).toBe(false) |
| 120 | + }) |
| 121 | + }) |
| 122 | +}) |
0 commit comments