3
3
*
4
4
* @group unit/logger/config
5
5
*/
6
+ import { beforeEach , describe , expect , it , jest } from '@jest/globals' ;
6
7
import { EnvironmentVariablesService } from '../../src/config/EnvironmentVariablesService.js' ;
7
8
8
9
describe ( 'Class: EnvironmentVariablesService' , ( ) => {
@@ -13,209 +14,185 @@ describe('Class: EnvironmentVariablesService', () => {
13
14
process . env = { ...ENVIRONMENT_VARIABLES } ;
14
15
} ) ;
15
16
16
- afterAll ( ( ) => {
17
- process . env = ENVIRONMENT_VARIABLES ;
18
- } ) ;
19
-
20
- describe ( 'Method: getAwsLogLevel' , ( ) => {
21
- it ( 'returns the value of the environment variable AWS_LAMBDA_LOG_LEVEL and aliases it as needed' , ( ) => {
22
- // Prepare
23
- process . env . AWS_LAMBDA_LOG_LEVEL = 'FATAL' ;
24
- const service = new EnvironmentVariablesService ( ) ;
17
+ it ( 'returns the value of the environment variable AWS_LAMBDA_LOG_LEVEL and aliases it as needed' , ( ) => {
18
+ // Prepare
19
+ process . env . AWS_LAMBDA_LOG_LEVEL = 'FATAL' ;
20
+ const service = new EnvironmentVariablesService ( ) ;
25
21
26
- // Act
27
- const value = service . getAwsLogLevel ( ) ;
22
+ // Act
23
+ const value = service . getAwsLogLevel ( ) ;
28
24
29
- // Assess
30
- expect ( value ) . toEqual ( 'CRITICAL' ) ;
31
- } ) ;
25
+ // Assess
26
+ expect ( value ) . toEqual ( 'CRITICAL' ) ;
32
27
} ) ;
33
28
34
- describe ( 'Method: getAwsRegion' , ( ) => {
35
- test ( 'it returns the value of the environment variable AWS_REGION' , ( ) => {
36
- // Prepare
37
- process . env . AWS_REGION = 'us-east-1' ;
38
- const service = new EnvironmentVariablesService ( ) ;
29
+ it ( 'returns the value of the environment variable AWS_REGION' , ( ) => {
30
+ // Prepare
31
+ process . env . AWS_REGION = 'us-east-1' ;
32
+ const service = new EnvironmentVariablesService ( ) ;
39
33
40
- // Act
41
- const value = service . getAwsRegion ( ) ;
34
+ // Act
35
+ const value = service . getAwsRegion ( ) ;
42
36
43
- // Assess
44
- expect ( value ) . toEqual ( 'us-east-1' ) ;
45
- } ) ;
37
+ // Assess
38
+ expect ( value ) . toEqual ( 'us-east-1' ) ;
46
39
} ) ;
47
40
48
- describe ( 'Method: getCurrentEnvironment' , ( ) => {
49
- test ( 'it returns the value of the environment variable AWS_REGION' , ( ) => {
50
- // Prepare
51
- process . env . ENVIRONMENT = 'stage' ;
52
- const service = new EnvironmentVariablesService ( ) ;
41
+ it ( 'returns the value of the environment variable AWS_REGION' , ( ) => {
42
+ // Prepare
43
+ process . env . ENVIRONMENT = 'stage' ;
44
+ const service = new EnvironmentVariablesService ( ) ;
53
45
54
- // Act
55
- const value = service . getCurrentEnvironment ( ) ;
46
+ // Act
47
+ const value = service . getCurrentEnvironment ( ) ;
56
48
57
- // Assess
58
- expect ( value ) . toEqual ( 'stage' ) ;
59
- } ) ;
49
+ // Assess
50
+ expect ( value ) . toEqual ( 'stage' ) ;
60
51
} ) ;
61
52
62
- describe ( 'Method: getFunctionMemory' , ( ) => {
63
- test ( 'it returns the value of the environment variable AWS_LAMBDA_FUNCTION_MEMORY_SIZE' , ( ) => {
64
- // Prepare
65
- process . env . AWS_LAMBDA_FUNCTION_MEMORY_SIZE = '123456' ;
66
- const service = new EnvironmentVariablesService ( ) ;
53
+ it ( 'returns the value of the environment variable AWS_LAMBDA_FUNCTION_MEMORY_SIZE' , ( ) => {
54
+ // Prepare
55
+ process . env . AWS_LAMBDA_FUNCTION_MEMORY_SIZE = '123456' ;
56
+ const service = new EnvironmentVariablesService ( ) ;
67
57
68
- // Act
69
- const value = service . getFunctionMemory ( ) ;
58
+ // Act
59
+ const value = service . getFunctionMemory ( ) ;
70
60
71
- // Assess
72
- expect ( value ) . toBe ( 123456 ) ;
73
- } ) ;
61
+ // Assess
62
+ expect ( value ) . toBe ( 123456 ) ;
74
63
} ) ;
75
64
76
- describe ( 'Method: getFunctionName' , ( ) => {
77
- test ( 'it returns the value of the environment variable AWS_LAMBDA_FUNCTION_NAME' , ( ) => {
78
- // Prepare
79
- process . env . AWS_LAMBDA_FUNCTION_NAME = 'my-lambda-function' ;
80
- const service = new EnvironmentVariablesService ( ) ;
65
+ it ( 'returns the value of the environment variable AWS_LAMBDA_FUNCTION_NAME' , ( ) => {
66
+ // Prepare
67
+ process . env . AWS_LAMBDA_FUNCTION_NAME = 'my-lambda-function' ;
68
+ const service = new EnvironmentVariablesService ( ) ;
81
69
82
- // Act
83
- const value = service . getFunctionName ( ) ;
70
+ // Act
71
+ const value = service . getFunctionName ( ) ;
84
72
85
- // Assess
86
- expect ( value ) . toEqual ( 'my-lambda-function' ) ;
87
- } ) ;
73
+ // Assess
74
+ expect ( value ) . toEqual ( 'my-lambda-function' ) ;
88
75
} ) ;
89
76
90
- describe ( 'Method: getFunctionVersion' , ( ) => {
91
- test ( 'it returns the value of the environment variable AWS_LAMBDA_FUNCTION_VERSION' , ( ) => {
92
- // Prepare
93
- process . env . AWS_LAMBDA_FUNCTION_VERSION = '1.4.0' ;
94
- const service = new EnvironmentVariablesService ( ) ;
77
+ it ( 'returns the value of the environment variable AWS_LAMBDA_FUNCTION_VERSION' , ( ) => {
78
+ // Prepare
79
+ process . env . AWS_LAMBDA_FUNCTION_VERSION = '1.4.0' ;
80
+ const service = new EnvironmentVariablesService ( ) ;
95
81
96
- // Act
97
- const value = service . getFunctionVersion ( ) ;
82
+ // Act
83
+ const value = service . getFunctionVersion ( ) ;
98
84
99
- // Assess
100
- expect ( value ) . toEqual ( '1.4.0' ) ;
101
- } ) ;
85
+ // Assess
86
+ expect ( value ) . toEqual ( '1.4.0' ) ;
102
87
} ) ;
103
88
104
- describe ( 'Method: getLogEvent' , ( ) => {
105
- test ( 'it returns true if the environment variable POWERTOOLS_LOGGER_LOG_EVENT is "true"' , ( ) => {
106
- // Prepare
107
- process . env . POWERTOOLS_LOGGER_LOG_EVENT = 'true' ;
108
- const service = new EnvironmentVariablesService ( ) ;
89
+ it ( 'returns true if the environment variable POWERTOOLS_LOGGER_LOG_EVENT is "true"' , ( ) => {
90
+ // Prepare
91
+ process . env . POWERTOOLS_LOGGER_LOG_EVENT = 'true' ;
92
+ const service = new EnvironmentVariablesService ( ) ;
109
93
110
- // Act
111
- const value = service . getLogEvent ( ) ;
94
+ // Act
95
+ const value = service . getLogEvent ( ) ;
112
96
113
- // Assess
114
- expect ( value ) . toEqual ( true ) ;
115
- } ) ;
97
+ // Assess
98
+ expect ( value ) . toEqual ( true ) ;
99
+ } ) ;
116
100
117
- test ( 'it returns false if the environment variable POWERTOOLS_LOGGER_LOG_EVENT is "false"', ( ) => {
118
- // Prepare
119
- process . env . POWERTOOLS_LOGGER_LOG_EVENT = 'false' ;
120
- const service = new EnvironmentVariablesService ( ) ;
101
+ it ( ' returns false if the environment variable POWERTOOLS_LOGGER_LOG_EVENT is "false"', ( ) => {
102
+ // Prepare
103
+ process . env . POWERTOOLS_LOGGER_LOG_EVENT = 'false' ;
104
+ const service = new EnvironmentVariablesService ( ) ;
121
105
122
- // Act
123
- const value = service . getLogEvent ( ) ;
106
+ // Act
107
+ const value = service . getLogEvent ( ) ;
124
108
125
- // Assess
126
- expect ( value ) . toEqual ( false ) ;
127
- } ) ;
109
+ // Assess
110
+ expect ( value ) . toEqual ( false ) ;
111
+ } ) ;
128
112
129
- test ( 'it returns false if the environment variable POWERTOOLS_LOGGER_LOG_EVENT is "somethingsilly"', ( ) => {
130
- // Prepare
131
- process . env . POWERTOOLS_LOGGER_LOG_EVENT = 'somethingsilly' ;
132
- const service = new EnvironmentVariablesService ( ) ;
113
+ it ( ' returns false if the environment variable POWERTOOLS_LOGGER_LOG_EVENT is "somethingsilly"', ( ) => {
114
+ // Prepare
115
+ process . env . POWERTOOLS_LOGGER_LOG_EVENT = 'somethingsilly' ;
116
+ const service = new EnvironmentVariablesService ( ) ;
133
117
134
- // Act
135
- const value = service . getLogEvent ( ) ;
118
+ // Act
119
+ const value = service . getLogEvent ( ) ;
136
120
137
- // Assess
138
- expect ( value ) . toEqual ( false ) ;
139
- } ) ;
121
+ // Assess
122
+ expect ( value ) . toEqual ( false ) ;
140
123
} ) ;
141
124
142
- describe ( 'Method: getLogLevel' , ( ) => {
143
- test ( 'it returns the value of the environment variable LOG_LEVEL when POWERTOOLS_LOG_LEVEL is not set' , ( ) => {
144
- // Prepare
145
- process . env . POWERTOOLS_LOG_LEVEL = undefined ;
146
- process . env . LOG_LEVEL = 'ERROR' ;
147
- const service = new EnvironmentVariablesService ( ) ;
125
+ it ( 'returns the value of the environment variable LOG_LEVEL when POWERTOOLS_LOG_LEVEL is not set' , ( ) => {
126
+ // Prepare
127
+ process . env . POWERTOOLS_LOG_LEVEL = undefined ;
128
+ process . env . LOG_LEVEL = 'ERROR' ;
129
+ const service = new EnvironmentVariablesService ( ) ;
148
130
149
- // Act
150
- const value = service . getLogLevel ( ) ;
131
+ // Act
132
+ const value = service . getLogLevel ( ) ;
151
133
152
- // Assess
153
- expect ( value ) . toEqual ( 'ERROR' ) ;
154
- } ) ;
134
+ // Assess
135
+ expect ( value ) . toEqual ( 'ERROR' ) ;
136
+ } ) ;
155
137
156
- test ( 'it returns the value of the environment variable POWERTOOLS_LOG_LEVEL when LOG_LEVEL one is also set', ( ) => {
157
- // Prepare
158
- process . env . LOG_LEVEL = 'WARN' ;
159
- process . env . POWERTOOLS_LOG_LEVEL = 'INFO' ;
160
- const service = new EnvironmentVariablesService ( ) ;
138
+ it ( ' returns the value of the environment variable POWERTOOLS_LOG_LEVEL when LOG_LEVEL one is also set', ( ) => {
139
+ // Prepare
140
+ process . env . LOG_LEVEL = 'WARN' ;
141
+ process . env . POWERTOOLS_LOG_LEVEL = 'INFO' ;
142
+ const service = new EnvironmentVariablesService ( ) ;
161
143
162
- // Act
163
- const value = service . getLogLevel ( ) ;
144
+ // Act
145
+ const value = service . getLogLevel ( ) ;
164
146
165
- // Assess
166
- expect ( value ) . toEqual ( 'INFO' ) ;
167
- } ) ;
147
+ // Assess
148
+ expect ( value ) . toEqual ( 'INFO' ) ;
149
+ } ) ;
168
150
169
- test ( 'it returns an empty value if neither POWERTOOLS_LOG_LEVEL nor LOG_LEVEL are set', ( ) => {
170
- // Prepare
171
- process . env . LOG_LEVEL = undefined ;
172
- process . env . POWERTOOLS_LOG_LEVEL = undefined ;
173
- const service = new EnvironmentVariablesService ( ) ;
151
+ it ( ' returns an empty value if neither POWERTOOLS_LOG_LEVEL nor LOG_LEVEL are set', ( ) => {
152
+ // Prepare
153
+ process . env . LOG_LEVEL = undefined ;
154
+ process . env . POWERTOOLS_LOG_LEVEL = undefined ;
155
+ const service = new EnvironmentVariablesService ( ) ;
174
156
175
- // Act
176
- const value = service . getLogLevel ( ) ;
157
+ // Act
158
+ const value = service . getLogLevel ( ) ;
177
159
178
- // Assess
179
- expect ( value ) . toEqual ( '' ) ;
180
- } ) ;
160
+ // Assess
161
+ expect ( value ) . toEqual ( '' ) ;
181
162
} ) ;
182
163
183
- describe ( 'Method: getSampleRateValue' , ( ) => {
184
- test ( 'it returns the value of the environment variable POWERTOOLS_LOGGER_SAMPLE_RATE' , ( ) => {
185
- // Prepare
186
- process . env . POWERTOOLS_LOGGER_SAMPLE_RATE = '0.01' ;
187
- const service = new EnvironmentVariablesService ( ) ;
164
+ it ( 'returns the value of the environment variable POWERTOOLS_LOGGER_SAMPLE_RATE' , ( ) => {
165
+ // Prepare
166
+ process . env . POWERTOOLS_LOGGER_SAMPLE_RATE = '0.01' ;
167
+ const service = new EnvironmentVariablesService ( ) ;
188
168
189
- // Act
190
- const value = service . getSampleRateValue ( ) ;
169
+ // Act
170
+ const value = service . getSampleRateValue ( ) ;
191
171
192
- // Assess
193
- expect ( value ) . toEqual ( 0.01 ) ;
194
- } ) ;
172
+ // Assess
173
+ expect ( value ) . toEqual ( 0.01 ) ;
195
174
} ) ;
196
175
197
- describe ( 'Method: getTimezone' , ( ) => {
198
- it ( 'returns the value of the TZ environment variable when set' , ( ) => {
199
- // Prepare
200
- process . env . TZ = 'Europe/London' ;
201
- const service = new EnvironmentVariablesService ( ) ;
176
+ it ( 'returns the value of the TZ environment variable when set' , ( ) => {
177
+ // Prepare
178
+ process . env . TZ = 'Europe/London' ;
179
+ const service = new EnvironmentVariablesService ( ) ;
202
180
203
- // Act
204
- const value = service . getTimezone ( ) ;
181
+ // Act
182
+ const value = service . getTimezone ( ) ;
205
183
206
- // Assess
207
- expect ( value ) . toEqual ( 'Europe/London' ) ;
208
- } ) ;
184
+ // Assess
185
+ expect ( value ) . toEqual ( 'Europe/London' ) ;
186
+ } ) ;
209
187
210
- it ( 'returns the default UTC value when no TZ is set' , ( ) => {
211
- // Prepare
212
- const service = new EnvironmentVariablesService ( ) ;
188
+ it ( 'returns the default UTC value when no TZ is set' , ( ) => {
189
+ // Prepare
190
+ const service = new EnvironmentVariablesService ( ) ;
213
191
214
- // Act
215
- const value = service . getTimezone ( ) ;
192
+ // Act
193
+ const value = service . getTimezone ( ) ;
216
194
217
- // Assess
218
- expect ( value ) . toEqual ( 'UTC' ) ;
219
- } ) ;
195
+ // Assess
196
+ expect ( value ) . toEqual ( 'UTC' ) ;
220
197
} ) ;
221
198
} ) ;
0 commit comments