refactor: Update environment variable setup in test-setup.sh

This code change updates the environment variable setup in the test-setup.sh script. The sed command is used to modify the config.env file, setting the NODE_ENV to 'test' and BILLING_ENABLED to 'true'. Additionally, the DATABASE_HOST is set to 'localhost', DATABASE_PORT to '5400', REDIS_HOST to 'localhost', REDIS_PORT to '6379', REDIS_DB to '0', and REDIS_USERNAME to 'default'. This improvement ensures that the test environment is properly configured with the correct values for testing.
This commit is contained in:
Simon Larsen 2024-06-03 13:37:23 +01:00
parent bc205a8686
commit 366b195152
No known key found for this signature in database
GPG Key ID: 96C5DCA24769DBCA
3 changed files with 28 additions and 12 deletions

View File

@ -116,8 +116,6 @@ describe('TeamMemberService', () => {
describe('onBeforeCreate', () => {
it('should throw exception if the user limit for a project is reached', async () => {
process.env['BILLING_ENABLED'] = 'true';
const SEATS_LIMIT: number = 5;
ProjectService.findOneById = jest.fn().mockResolvedValue({

View File

@ -1,13 +1,5 @@
import '../../Utils/Environment';
// Env vars are actually changed in CommonServer/test-setup.sh
process.env['NODE_ENV'] = 'test';
process.env['BILLING_ENABLED'] = 'true';
process.env['DATABASE_HOST'] = 'localhost';
process.env['DATABASE_PORT'] = '5400';
process.env['REDIS_HOST'] = 'localhost';
process.env['REDIS_PORT'] = '6379';
process.env['REDIS_DB'] = '0';
process.env['REDIS_USERNAME'] = 'default';

View File

@ -6,4 +6,30 @@ cd ..
# Run Preinstall.
npm run prerun
# Run Postgres
# Change all of the following env vars in config.env
# process.env['NODE_ENV'] = 'test';
# process.env['BILLING_ENABLED'] = 'true';
# process.env['DATABASE_HOST'] = 'localhost';
# process.env['DATABASE_PORT'] = '5400';
# process.env['REDIS_HOST'] = 'localhost';
# process.env['REDIS_PORT'] = '6379';
# process.env['REDIS_DB'] = '0';
# process.env['REDIS_USERNAME'] = 'default';
# Using sed
sed -i 's/.*NODE_ENV.*/NODE_ENV=test/' config.env
sed -i 's/.*BILLING_ENABLED.*/BILLING_ENABLED=true/' config.env
sed -i 's/.*DATABASE_HOST.*/DATABASE_HOST=localhost/' config.env
sed -i 's/.*DATABASE_PORT.*/DATABASE_PORT=5400/' config.env
sed -i 's/.*REDIS_HOST.*/REDIS_HOST=localhost/' config.env
sed -i 's/.*REDIS_PORT.*/REDIS_PORT=6379/' config.env
sed -i 's/.*REDIS_DB.*/REDIS_DB=0/' config.env
sed -i 's/.*REDIS_USERNAME.*/REDIS_USERNAME=default/' config.env
export $(grep -v '^#' config.env | xargs) && docker compose -f docker-compose.dev.yml up -d postgres