forked from Movalabs-crew/mova-store
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.test.ts
More file actions
62 lines (51 loc) · 1.74 KB
/
Copy pathenv.test.ts
File metadata and controls
62 lines (51 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { isAdminEmail, isDevelopment, isProduction } from "../../lib/env";
describe("isAdminEmail", () => {
beforeEach(() => {
vi.stubEnv("NEXT_PUBLIC_ADMIN_EMAILS", "admin@test.com,admin2@test.com");
});
afterEach(() => {
vi.unstubAllEnvs();
});
it("returns true for admin emails", () => {
expect(isAdminEmail("admin@test.com")).toBe(true);
expect(isAdminEmail("admin2@test.com")).toBe(true);
});
it("is case insensitive", () => {
expect(isAdminEmail("ADMIN@TEST.COM")).toBe(true);
expect(isAdminEmail("Admin@Test.Com")).toBe(true);
});
it("returns false for non-admin emails", () => {
expect(isAdminEmail("user@test.com")).toBe(false);
expect(isAdminEmail("notadmin@test.com")).toBe(false);
});
it("returns false for null/undefined", () => {
expect(isAdminEmail(null)).toBe(false);
expect(isAdminEmail(undefined)).toBe(false);
expect(isAdminEmail("")).toBe(false);
});
it("handles empty admin list", () => {
vi.stubEnv("NEXT_PUBLIC_ADMIN_EMAILS", "");
expect(isAdminEmail("admin@test.com")).toBe(false);
});
});
describe("isDevelopment", () => {
it("returns true in development", () => {
vi.stubEnv("NODE_ENV", "development");
expect(isDevelopment()).toBe(true);
});
it("returns false in production", () => {
vi.stubEnv("NODE_ENV", "production");
expect(isDevelopment()).toBe(false);
});
});
describe("isProduction", () => {
it("returns true in production", () => {
vi.stubEnv("NODE_ENV", "production");
expect(isProduction()).toBe(true);
});
it("returns false in development", () => {
vi.stubEnv("NODE_ENV", "development");
expect(isProduction()).toBe(false);
});
});