@@ -34,6 +34,53 @@ test.group('Env Add command', () => {
3434 await assert . fileContains ( './start/env.ts' , 'VARIABLE: Env.schema.string()' )
3535 } )
3636
37+ test ( 'add secret env variable using the type flag' , async ( { assert, fs } ) => {
38+ await fs . createJson ( 'tsconfig.json' , { } )
39+ await fs . create ( '.env' , '' )
40+ await fs . create ( '.env.example' , '' )
41+ await fs . create (
42+ './start/env.ts' ,
43+ `import { Env } from '@adonisjs/core/env'
44+ export default await Env.create(new URL('../', import.meta.url), {})`
45+ )
46+
47+ const ace = await new AceFactory ( ) . make ( fs . baseUrl )
48+ await ace . app . init ( )
49+ ace . ui . switchMode ( 'raw' )
50+
51+ const command = await ace . create ( EnvAdd , [ 'api_key' , 'my_secret' , '--type=secret' ] )
52+ await command . exec ( )
53+
54+ await assert . fileContains ( '.env' , 'API_KEY=my_secret' )
55+ await assert . fileContains ( '.env.example' , 'API_KEY=' )
56+ await assert . fileNotContains ( '.env.example' , 'my_secret' )
57+ await assert . fileContains ( './start/env.ts' , 'API_KEY: Env.schema.secret()' )
58+ } )
59+
60+ test ( 'select secret type from the prompt' , async ( { assert, fs } ) => {
61+ await fs . createJson ( 'tsconfig.json' , { } )
62+ await fs . create ( '.env' , '' )
63+ await fs . create ( '.env.example' , '' )
64+ await fs . create (
65+ './start/env.ts' ,
66+ `import { Env } from '@adonisjs/core/env'
67+ export default await Env.create(new URL('../', import.meta.url), {})`
68+ )
69+
70+ const ace = await new AceFactory ( ) . make ( fs . baseUrl )
71+ await ace . app . init ( )
72+ ace . ui . switchMode ( 'raw' )
73+
74+ const command = await ace . create ( EnvAdd , [ 'api_key' , 'my_secret' ] )
75+ command . prompt . trap ( 'Select the variable type' ) . replyWith ( 'secret' )
76+ await command . exec ( )
77+
78+ await assert . fileContains ( '.env' , 'API_KEY=my_secret' )
79+ await assert . fileContains ( '.env.example' , 'API_KEY=' )
80+ await assert . fileNotContains ( '.env.example' , 'my_secret' )
81+ await assert . fileContains ( './start/env.ts' , 'API_KEY: Env.schema.secret()' )
82+ } )
83+
3784 test ( 'convert variable to screaming snake case' , async ( { assert, fs } ) => {
3885 await fs . createJson ( 'tsconfig.json' , { } )
3986 await fs . create ( '.env' , '' )
0 commit comments