@@ -10,7 +10,8 @@ describe('config:generate command', () => {
10
10
beforeEach ( async ( ) => {
11
11
// fail-safe: delete any existing logchimp config at root directory
12
12
const currentDirectory = await process . cwd ( )
13
- await fs . removeSync ( `${ currentDirectory } /logchimp.config.json` )
13
+ fs . removeSync ( `${ currentDirectory } /logchimp.config.json` )
14
+ fs . removeSync ( `${ currentDirectory } /.env` )
14
15
} )
15
16
16
17
describe ( 'generate config' , ( ) => {
@@ -27,6 +28,7 @@ describe('config:generate command', () => {
27
28
28
29
// server
29
30
expect ( config . server . local ) . toBe ( false )
31
+ expect ( config . server . host ) . toBe ( '127.0.0.1' )
30
32
expect ( config . server . port ) . toBe ( 3000 )
31
33
32
34
// database
@@ -41,6 +43,7 @@ describe('config:generate command', () => {
41
43
const command = await runCommand ( [
42
44
'config:generate' ,
43
45
'--port=80' ,
46
+ '--host=0.0.0.0' ,
44
47
'--secretkey=mySecretKey' ,
45
48
'--dbhost=postgres-db.logchimp.codecarrot.net' ,
46
49
'--dbuser=pg_db_user' ,
@@ -63,6 +66,7 @@ describe('config:generate command', () => {
63
66
64
67
// server
65
68
expect ( config . server . local ) . toBe ( false )
69
+ expect ( config . server . host ) . toBe ( '0.0.0.0' )
66
70
expect ( config . server . port ) . toBe ( 80 )
67
71
expect ( config . server . secretkey ) . toBe ( 'mySecretKey' )
68
72
// database
@@ -141,6 +145,7 @@ describe('config:generate command', () => {
141
145
fs . writeFileSync (
142
146
`${ currentDirectory } /.env` ,
143
147
`LOGCHIMP_SERVER_PORT=3000
148
+ LOGCHIMP_SECRET_HOST=0.0.0.0
144
149
LOGCHIMP_SECRET_KEY=secret-key
145
150
LOGCHIMP_DB_HOST=localhost
146
151
LOGCHIMP_DB_PORT=5432
@@ -166,23 +171,66 @@ LOGCHIMP_MAIL_PASSWORD=mail_password`
166
171
const isConfigEmpty = _ . isEmpty ( config )
167
172
expect ( isConfigEmpty ) . toBe ( false )
168
173
169
- // server
170
- expect ( config . server . secretkey ) . toBe ( 'secret-key' )
171
- expect ( config . server . port ) . toBe ( 3000 )
172
-
173
- // database
174
- expect ( config . database . host ) . toBe ( 'localhost' )
175
- expect ( config . database . user ) . toBe ( 'logchimp' )
176
- expect ( config . database . password ) . toBe ( 'secret-password' )
177
- expect ( config . database . name ) . toBe ( 'logchimpDB' )
178
- expect ( config . database . port ) . toBe ( 5432 )
179
- expect ( config . database . ssl ) . toBe ( true )
180
-
181
- // mail
182
- expect ( config . mail . service ) . toBe ( 'service' )
183
- expect ( config . mail . host ) . toBe ( 'mail_host' )
184
- expect ( config . mail . user ) . toBe ( 'mail_username' )
185
- expect ( config . mail . password ) . toBe ( 'mail_password' )
186
- expect ( config . mail . port ) . toBe ( 587 )
174
+ // server
175
+ expect ( config . server . host ) . toBe ( '0.0.0.0' )
176
+ expect ( config . server . secretkey ) . toBe ( 'secret-key' )
177
+ expect ( config . server . port ) . toBe ( 3000 )
178
+
179
+ // database
180
+ expect ( config . database . host ) . toBe ( 'localhost' )
181
+ expect ( config . database . user ) . toBe ( 'logchimp' )
182
+ expect ( config . database . password ) . toBe ( 'secret-password' )
183
+ expect ( config . database . name ) . toBe ( 'logchimpDB' )
184
+ expect ( config . database . port ) . toBe ( 5432 )
185
+ expect ( config . database . ssl ) . toBe ( true )
186
+
187
+ // mail
188
+ expect ( config . mail . service ) . toBe ( 'service' )
189
+ expect ( config . mail . host ) . toBe ( 'mail_host' )
190
+ expect ( config . mail . user ) . toBe ( 'mail_username' )
191
+ expect ( config . mail . password ) . toBe ( 'mail_password' )
192
+ expect ( config . mail . port ) . toBe ( 587 )
193
+ } )
194
+
195
+ it ( 'with --env flag and default values' , async ( ) => {
196
+ const currentDirectory = await process . cwd ( )
197
+
198
+ // create .env file if not already present
199
+ const envIsPresent = fs . existsSync ( `${ currentDirectory } /.env` )
200
+
201
+ if ( ! envIsPresent ) {
202
+ // intentionally creating an empty .env file
203
+ fs . writeFileSync ( `${ currentDirectory } /.env` , '' )
204
+ }
205
+
206
+ // generate config file
207
+ const command = await runCommand ( [ 'config:generate' , '--env' ] )
208
+
209
+ expect ( command . stdout ) . toContain ( 'LogChimp configuration file succesfully created from environment variables' )
210
+
211
+ // validate configuration file
212
+ const config = fs . readJsonSync ( `${ currentDirectory } /logchimp.config.json` )
213
+ const isConfigEmpty = _ . isEmpty ( config )
214
+ expect ( isConfigEmpty ) . toBe ( false )
215
+
216
+ // server
217
+ expect ( config . server . host ) . toBe ( '127.0.0.1' )
218
+ expect ( config . server . secretkey ) . toBeUndefined ( )
219
+ expect ( config . server . port ) . toBe ( 3000 )
220
+
221
+ // database
222
+ expect ( config . database . host ) . toBeUndefined ( )
223
+ expect ( config . database . user ) . toBeUndefined ( )
224
+ expect ( config . database . password ) . toBeUndefined ( )
225
+ expect ( config . database . name ) . toBeUndefined ( )
226
+ expect ( config . database . port ) . toBe ( 5432 )
227
+ expect ( config . database . ssl ) . toBe ( true )
228
+
229
+ // mail
230
+ expect ( config . mail . service ) . toBeUndefined ( )
231
+ expect ( config . mail . host ) . toBeUndefined ( )
232
+ expect ( config . mail . user ) . toBeUndefined ( )
233
+ expect ( config . mail . password ) . toBeUndefined ( )
234
+ expect ( config . mail . port ) . toBe ( 587 )
187
235
} )
188
236
} )
0 commit comments