env-store-session-messages.test.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { describe, expect, it, afterEach } from "vitest";
  2. import { EnvSchema } from "@/lib/config/env.schema";
  3. describe("EnvSchema - STORE_SESSION_MESSAGES", () => {
  4. // Store original env
  5. const originalEnv = process.env.STORE_SESSION_MESSAGES;
  6. afterEach(() => {
  7. // Restore original env
  8. if (originalEnv === undefined) {
  9. delete process.env.STORE_SESSION_MESSAGES;
  10. } else {
  11. process.env.STORE_SESSION_MESSAGES = originalEnv;
  12. }
  13. });
  14. it("should default to false when not set", () => {
  15. delete process.env.STORE_SESSION_MESSAGES;
  16. const result = EnvSchema.parse(process.env);
  17. expect(result.STORE_SESSION_MESSAGES).toBe(false);
  18. });
  19. it("should parse 'true' as true", () => {
  20. process.env.STORE_SESSION_MESSAGES = "true";
  21. const result = EnvSchema.parse(process.env);
  22. expect(result.STORE_SESSION_MESSAGES).toBe(true);
  23. });
  24. it("should parse 'false' as false", () => {
  25. process.env.STORE_SESSION_MESSAGES = "false";
  26. const result = EnvSchema.parse(process.env);
  27. expect(result.STORE_SESSION_MESSAGES).toBe(false);
  28. });
  29. it("should parse '0' as false", () => {
  30. process.env.STORE_SESSION_MESSAGES = "0";
  31. const result = EnvSchema.parse(process.env);
  32. expect(result.STORE_SESSION_MESSAGES).toBe(false);
  33. });
  34. it("should parse '1' as true", () => {
  35. process.env.STORE_SESSION_MESSAGES = "1";
  36. const result = EnvSchema.parse(process.env);
  37. expect(result.STORE_SESSION_MESSAGES).toBe(true);
  38. });
  39. });