-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: 🧪 Service Configurations test cases
- Loading branch information
1 parent
3ba5a8e
commit 546d2d3
Showing
1 changed file
with
52 additions
and
36 deletions.
There are no files selected for viewing
88 changes: 52 additions & 36 deletions
88
libs/application-config/src/lib/applications-config.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,67 @@ | ||
import { | ||
gatewayConfig, | ||
userSubGraph, | ||
taskSubGraph, | ||
} from './applications-config'; | ||
|
||
describe('applicationsConfig', () => { | ||
describe('environment variables', () => { | ||
const originalEnv = process.env; | ||
|
||
beforeEach(() => { | ||
jest.resetModules(); | ||
process.env = { ...originalEnv }; | ||
}); | ||
describe('Service Configurations', () => { | ||
const originalEnv = process.env; | ||
|
||
beforeEach(() => { | ||
jest.resetModules(); | ||
process.env = { ...originalEnv }; | ||
}); | ||
|
||
afterEach(() => { | ||
process.env = originalEnv; | ||
}); | ||
|
||
afterAll(() => { | ||
process.env = originalEnv; | ||
it('should use default values when environment variables are not set', () => { | ||
const { | ||
gatewayConfig, | ||
userSubGraph, | ||
taskSubGraph, | ||
} = require('./applications-config'); | ||
|
||
expect(gatewayConfig).toEqual({ | ||
host: 'localhost', | ||
port: '3333', | ||
}); | ||
|
||
it('should use environment variables when provided', () => { | ||
process.env['GATEWAY_HOST'] = 'custom-host'; | ||
process.env['GATEWAY_PORT'] = '4000'; | ||
expect(gatewayConfig.host).toBe('custom-host'); | ||
expect(gatewayConfig.port).toBe(4000); | ||
expect(userSubGraph).toEqual({ | ||
host: 'localhost', | ||
port: '15001', | ||
}); | ||
|
||
it('should use default values when environment variables are not set', () => { | ||
delete process.env['GATEWAY_HOST']; | ||
delete process.env['GATEWAY_PORT']; | ||
expect(gatewayConfig.host).toBeDefined(); | ||
expect(gatewayConfig.port).toBeDefined(); | ||
expect(taskSubGraph).toEqual({ | ||
host: 'localhost', | ||
port: '15002', | ||
}); | ||
}); | ||
|
||
describe('configuration objects', () => { | ||
it('should have required properties for gateway config', () => { | ||
expect(gatewayConfig).toHaveProperty('host'); | ||
expect(gatewayConfig).toHaveProperty('port'); | ||
it('should use environment variables when they are set', () => { | ||
process.env['GATEWAY_HOST'] = 'gateway.example.com'; | ||
process.env['GATEWAY_PORT'] = '4000'; | ||
process.env['USER_HOST'] = 'user.example.com'; | ||
process.env['USER_PORT'] = '5000'; | ||
process.env['TASK_HOST'] = 'task.example.com'; | ||
process.env['TASK_PORT'] = '6000'; | ||
|
||
jest.resetModules(); | ||
|
||
const { | ||
gatewayConfig, | ||
userSubGraph, | ||
taskSubGraph, | ||
} = require('./applications-config'); | ||
|
||
expect(gatewayConfig).toEqual({ | ||
host: 'gateway.example.com', | ||
port: '4000', | ||
}); | ||
|
||
it('should have required properties for user subgraph', () => { | ||
expect(userSubGraph).toHaveProperty('host'); | ||
expect(userSubGraph).toHaveProperty('port'); | ||
expect(userSubGraph).toEqual({ | ||
host: 'user.example.com', | ||
port: '5000', | ||
}); | ||
|
||
it('should have required properties for task subgraph', () => { | ||
expect(taskSubGraph).toHaveProperty('host'); | ||
expect(taskSubGraph).toHaveProperty('port'); | ||
expect(taskSubGraph).toEqual({ | ||
host: 'task.example.com', | ||
port: '6000', | ||
}); | ||
}); | ||
}); |