@@ -6,21 +6,17 @@ import { LOGS_PREFIX_INVALID_CONFIG } from '../../data-types/constants';
66vi . mock ( '@aws-lambda-powertools/logger' ) ;
77
88describe ( 'AppConfigService' , ( ) => {
9- const OLD_ENV = process . env ;
10-
119 beforeEach ( ( ) => {
1210 vi . clearAllMocks ( ) ;
1311 vi . resetModules ( ) ;
14- process . env = { ...OLD_ENV } ;
15- delete process . env [ 'NODE_ENV' ] ;
1612 } ) ;
1713
1814 afterEach ( ( ) => {
19- process . env = OLD_ENV ;
15+ vi . unstubAllEnvs ( ) ;
2016 } ) ;
2117
2218 it ( 'should throw an error if the environment variable AWS_REGION is undefined' , ( ) => {
23- process . env [ 'AWS_REGION' ] = undefined ;
19+ vi . stubEnv ( 'AWS_REGION' , '' ) ;
2420 const appConfig = AppConfigService . getInstance ( ) ;
2521 const expectedMessage = 'Invalid configuration - Environment variable AWS_REGION is not defined.' ;
2622 expect ( ( ) => appConfig . awsRegion ) . toThrow ( new InvalidEnvironmentVariableError ( expectedMessage ) ) ;
@@ -31,7 +27,7 @@ describe('AppConfigService', () => {
3127 } ) ;
3228
3329 it ( 'should throw an error if the environment variable TABLE_NAME is equal to an empty string' , ( ) => {
34- process . env [ 'TABLE_NAME' ] = '' ;
30+ vi . stubEnv ( 'TABLE_NAME' , '' ) ;
3531 const appConfig = AppConfigService . getInstance ( ) ;
3632 const expectedMessage = 'Invalid configuration - Environment variable TABLE_NAME is not defined.' ;
3733 expect ( ( ) => appConfig . tableName ) . toThrow ( new InvalidEnvironmentVariableError ( expectedMessage ) ) ;
@@ -42,7 +38,7 @@ describe('AppConfigService', () => {
4238 } ) ;
4339
4440 it ( 'should throw an error if the environment variable DELETED_ACCOUNT_RETENTION_SECONDS is equal to an empty string' , ( ) => {
45- process . env [ 'DELETED_ACCOUNT_RETENTION_SECONDS' ] = '' ;
41+ vi . stubEnv ( 'DELETED_ACCOUNT_RETENTION_SECONDS' , '' ) ;
4642 const appConfig = AppConfigService . getInstance ( ) ;
4743 const expectedMessage =
4844 'Invalid configuration - Environment variable DELETED_ACCOUNT_RETENTION_SECONDS is not defined.' ;
@@ -54,7 +50,7 @@ describe('AppConfigService', () => {
5450 } ) ;
5551
5652 it ( 'should throw an error if the environment variable CLOUDWATCH_METRICS_NAMESPACE is equal to an empty string' , ( ) => {
57- process . env [ 'CLOUDWATCH_METRICS_NAMESPACE' ] = '' ;
53+ vi . stubEnv ( 'CLOUDWATCH_METRICS_NAMESPACE' , '' ) ;
5854 const appConfig = AppConfigService . getInstance ( ) ;
5955 const expectedMessage = 'Invalid configuration - Environment variable CLOUDWATCH_METRICS_NAMESPACE is not defined.' ;
6056 expect ( ( ) => appConfig . cloudWatchMetricsWorkSpace ) . toThrow ( new InvalidEnvironmentVariableError ( expectedMessage ) ) ;
@@ -65,7 +61,7 @@ describe('AppConfigService', () => {
6561 } ) ;
6662
6763 it ( 'should throw an error if the environment variable TXMA_QUEUE_URL is not a url' , ( ) => {
68- process . env [ 'TXMA_QUEUE_URL' ] = 'notAURL' ;
64+ vi . stubEnv ( 'TXMA_QUEUE_URL' , 'notAURL' ) ;
6965 const appConfig = AppConfigService . getInstance ( ) ;
7066 const expectedMessage = `${ LOGS_PREFIX_INVALID_CONFIG } Environment variable TXMA_QUEUE_URL is not a valid HTTPS URL (notAURL).` ;
7167 expect ( ( ) => appConfig . txmaEgressQueueUrl ) . toThrow ( new InvalidEnvironmentVariableError ( expectedMessage ) ) ;
@@ -87,7 +83,7 @@ describe('AppConfigService', () => {
8783 } ) ;
8884
8985 it ( 'should throw an error if the environmental variable is not a number' , ( ) => {
90- process . env [ 'DELETED_ACCOUNT_RETENTION_SECONDS' ] = 'string' ;
86+ vi . stubEnv ( 'DELETED_ACCOUNT_RETENTION_SECONDS' , 'string' ) ;
9187 const expectedMessage =
9288 'Invalid configuration - Environment variable DELETED_ACCOUNT_RETENTION_SECONDS is not a number.' ;
9389 const appConfig = AppConfigService . getInstance ( ) ;
0 commit comments