Files
x402-base-facilitator/test/unit/misc/config.js
T

63 lines
1.7 KiB
JavaScript
Raw Normal View History

2022-09-17 10:10:39 -07:00
/*
Unit tests for the config directory
*/
import { assert } from 'chai'
2022-09-17 10:10:39 -07:00
let currentEnv
describe('#config', () => {
before(() => {
// Backup the current environment setting.
currentEnv = process.env.SVC_ENV
2026-02-02 18:54:18 -07:00
// Clear SVC_ENV for the first test to ensure default behavior
delete process.env.SVC_ENV
2022-09-17 10:10:39 -07:00
})
after(() => {
// Restore the environment setting before starting these tests.
2026-02-02 18:54:18 -07:00
if (currentEnv) {
process.env.SVC_ENV = currentEnv
} else {
delete process.env.SVC_ENV
}
2022-09-17 10:10:39 -07:00
})
it('Should return development environment config by default', async () => {
2026-02-02 18:54:18 -07:00
// Ensure SVC_ENV is not set for this test
delete process.env.SVC_ENV
const importedConfig = await import('../../../config/index.js?foo=bar0')
const config = importedConfig.default
// console.log('config: ', config)
assert.equal(config.env, 'dev')
})
it('Should return test environment config', async () => {
// Hack to dynamically import a library multiple times:
// https://github.com/denoland/deno/issues/6946
process.env.SVC_ENV = 'test'
const importedConfig2 = await import('../../../config/index.js?foo=bar1')
const config = importedConfig2.default
2022-09-17 10:10:39 -07:00
// console.log('config: ', config)
assert.equal(config.env, 'test')
})
2024-03-23 17:42:59 -07:00
it('Should return prod environment config', async () => {
process.env.SVC_ENV = 'prod'
2024-03-23 17:42:59 -07:00
process.env.WALLET_INTERFACE = 'web2'
process.env.APISERVER = 'https://api.fullstack.cash/v5/'
await import('../../../config/env/common.js?foo=bar2')
const importedConfig3 = await import('../../../config/index.js?foo=bar2')
const config = importedConfig3.default
// console.log('config: ', config)
assert.equal(config.env, 'prod')
2022-09-17 10:10:39 -07:00
})
})