constants.test.ts105 lines · main
| 1 | import { beforeEach, describe, expect, it, vi } from 'vitest' |
| 2 | |
| 3 | describe('api/self-hosted/constants', () => { |
| 4 | beforeEach(() => { |
| 5 | vi.resetModules() |
| 6 | }) |
| 7 | |
| 8 | describe('ENCRYPTION_KEY', () => { |
| 9 | it('should use PG_META_CRYPTO_KEY when set', async () => { |
| 10 | vi.stubEnv('PG_META_CRYPTO_KEY', 'my-secret-key-123') |
| 11 | const { ENCRYPTION_KEY } = await import('./constants') |
| 12 | expect(ENCRYPTION_KEY).toBe('my-secret-key-123') |
| 13 | }) |
| 14 | |
| 15 | it('should use SAMPLE_KEY as default', async () => { |
| 16 | vi.stubEnv('PG_META_CRYPTO_KEY', '') |
| 17 | const { ENCRYPTION_KEY } = await import('./constants') |
| 18 | expect(ENCRYPTION_KEY).toBe('SAMPLE_KEY') |
| 19 | }) |
| 20 | }) |
| 21 | |
| 22 | describe('POSTGRES_PORT', () => { |
| 23 | it('should use POSTGRES_PORT when set', async () => { |
| 24 | vi.stubEnv('POSTGRES_PORT', '5433') |
| 25 | const { POSTGRES_PORT } = await import('./constants') |
| 26 | expect(POSTGRES_PORT).toBe(5433) |
| 27 | }) |
| 28 | |
| 29 | it('should default to 5432', async () => { |
| 30 | vi.stubEnv('POSTGRES_PORT', '') |
| 31 | const { POSTGRES_PORT } = await import('./constants') |
| 32 | expect(POSTGRES_PORT).toBe(5432) |
| 33 | }) |
| 34 | }) |
| 35 | |
| 36 | describe('POSTGRES_HOST', () => { |
| 37 | it('should use POSTGRES_HOST when set', async () => { |
| 38 | vi.stubEnv('POSTGRES_HOST', 'my-db-host.example.com') |
| 39 | const { POSTGRES_HOST } = await import('./constants') |
| 40 | expect(POSTGRES_HOST).toBe('my-db-host.example.com') |
| 41 | }) |
| 42 | |
| 43 | it('should default to db', async () => { |
| 44 | vi.stubEnv('POSTGRES_HOST', '') |
| 45 | const { POSTGRES_HOST } = await import('./constants') |
| 46 | expect(POSTGRES_HOST).toBe('db') |
| 47 | }) |
| 48 | }) |
| 49 | |
| 50 | describe('POSTGRES_DATABASE', () => { |
| 51 | it('should use POSTGRES_DB when set', async () => { |
| 52 | vi.stubEnv('POSTGRES_DB', 'my_database') |
| 53 | const { POSTGRES_DATABASE } = await import('./constants') |
| 54 | expect(POSTGRES_DATABASE).toBe('my_database') |
| 55 | }) |
| 56 | |
| 57 | it('should default to postgres', async () => { |
| 58 | vi.stubEnv('POSTGRES_DB', '') |
| 59 | const { POSTGRES_DATABASE } = await import('./constants') |
| 60 | expect(POSTGRES_DATABASE).toBe('postgres') |
| 61 | }) |
| 62 | }) |
| 63 | |
| 64 | describe('POSTGRES_PASSWORD', () => { |
| 65 | it('should use POSTGRES_PASSWORD when set', async () => { |
| 66 | vi.stubEnv('POSTGRES_PASSWORD', 'super-secret-password') |
| 67 | const { POSTGRES_PASSWORD } = await import('./constants') |
| 68 | expect(POSTGRES_PASSWORD).toBe('super-secret-password') |
| 69 | }) |
| 70 | |
| 71 | it('should default to postgres', async () => { |
| 72 | vi.stubEnv('POSTGRES_PASSWORD', '') |
| 73 | const { POSTGRES_PASSWORD } = await import('./constants') |
| 74 | expect(POSTGRES_PASSWORD).toBe('postgres') |
| 75 | }) |
| 76 | }) |
| 77 | |
| 78 | describe('POSTGRES_USER_READ_WRITE', () => { |
| 79 | it('should use POSTGRES_USER_READ_WRITE when set', async () => { |
| 80 | vi.stubEnv('POSTGRES_USER_READ_WRITE', 'custom_admin') |
| 81 | const { POSTGRES_USER_READ_WRITE } = await import('./constants') |
| 82 | expect(POSTGRES_USER_READ_WRITE).toBe('custom_admin') |
| 83 | }) |
| 84 | |
| 85 | it('should default to briven_admin', async () => { |
| 86 | vi.stubEnv('POSTGRES_USER_READ_WRITE', '') |
| 87 | const { POSTGRES_USER_READ_WRITE } = await import('./constants') |
| 88 | expect(POSTGRES_USER_READ_WRITE).toBe('briven_admin') |
| 89 | }) |
| 90 | }) |
| 91 | |
| 92 | describe('POSTGRES_USER_READ_ONLY', () => { |
| 93 | it('should use POSTGRES_USER_READ_ONLY when set', async () => { |
| 94 | vi.stubEnv('POSTGRES_USER_READ_ONLY', 'custom_readonly') |
| 95 | const { POSTGRES_USER_READ_ONLY } = await import('./constants') |
| 96 | expect(POSTGRES_USER_READ_ONLY).toBe('custom_readonly') |
| 97 | }) |
| 98 | |
| 99 | it('should default to briven_read_only_user', async () => { |
| 100 | vi.stubEnv('POSTGRES_USER_READ_ONLY', '') |
| 101 | const { POSTGRES_USER_READ_ONLY } = await import('./constants') |
| 102 | expect(POSTGRES_USER_READ_ONLY).toBe('briven_read_only_user') |
| 103 | }) |
| 104 | }) |
| 105 | }) |