@@ -46,6 +46,17 @@ describe('load config', () => {
4646 expect ( config ) . toEqual ( mockConfig )
4747 } )
4848
49+ test ( 'standalone app config with database' , async ( ) => {
50+ global . loadFixtureApp ( 'app-with-database' )
51+ config = await appConfig . load ( )
52+ expect ( config . all . application . database ) . toEqual ( {
53+ 'auto-provision' : true ,
54+ region : 'emea'
55+ } )
56+ expect ( config . all . application . app . hasBackend ) . toBe ( true )
57+ expect ( config . all . application . app . hasFrontend ) . toBe ( true )
58+ } )
59+
4960 test ( 'not in an app' , async ( ) => {
5061 global . loadFixtureApp ( 'not-in-app' )
5162 await expect ( appConfig . load ( ) ) . rejects . toThrow ( new Error ( 'ENOENT: no such file or directory, open \'package.json\'' ) )
@@ -1064,3 +1075,142 @@ describe('coalesce config', () => {
10641075 expect ( coalesced . includeIndex [ 'application.runtimeManifest.packages.my-app-package.actions.action.function' ] ) . toEqual ( { file : 'app/myactions/action.config.yaml' , key : 'function' } )
10651076 } )
10661077} )
1078+
1079+ describe ( 'database config' , ( ) => {
1080+ beforeEach ( async ( ) => {
1081+ mockAIOConfig . get . mockImplementation ( k => global . fakeConfig . tvm )
1082+ process . chdir ( '/' )
1083+ global . fakeFileSystem . clear ( )
1084+ libEnv . getCliEnv . mockReturnValue ( 'prod' )
1085+ } )
1086+
1087+ test ( 'valid database configuration' , async ( ) => {
1088+ global . fakeFileSystem . addJson ( {
1089+ '/package.json' : '{"name": "test-app", "version": "1.0.0"}' ,
1090+ '/app.config.yaml' : `
1091+ application:
1092+ runtimeManifest:
1093+ database:
1094+ auto-provision: true
1095+ region: 'emea'
1096+ packages:
1097+ my-app-package:
1098+ actions:
1099+ action:
1100+ function: 'actions/hello.js'
1101+ web: true
1102+ `
1103+ } )
1104+ const config = await appConfig . load ( )
1105+ expect ( config . all . application . database ) . toEqual ( {
1106+ 'auto-provision' : true ,
1107+ region : 'emea'
1108+ } )
1109+ } )
1110+
1111+ test ( 'database configuration with auto-provision true' , async ( ) => {
1112+ global . fakeFileSystem . addJson ( {
1113+ '/package.json' : '{"name": "test-app", "version": "1.0.0"}' ,
1114+ '/app.config.yaml' : `
1115+ application:
1116+ runtimeManifest:
1117+ database:
1118+ auto-provision: true
1119+ packages:
1120+ my-app-package:
1121+ actions:
1122+ action:
1123+ function: 'actions/hello.js'
1124+ web: true
1125+ `
1126+ } )
1127+ const config = await appConfig . load ( )
1128+ expect ( config . all . application . database ) . toEqual ( {
1129+ 'auto-provision' : true ,
1130+ region : 'amer'
1131+ } )
1132+ } )
1133+
1134+ test ( 'database configuration with empty fields' , async ( ) => {
1135+ global . fakeFileSystem . addJson ( {
1136+ '/package.json' : '{"name": "test-app", "version": "1.0.0"}' ,
1137+ '/app.config.yaml' : `
1138+ application:
1139+ runtimeManifest:
1140+ database: {}
1141+ packages:
1142+ my-app-package:
1143+ actions:
1144+ action:
1145+ function: 'actions/hello.js'
1146+ web: true
1147+ `
1148+ } )
1149+ await expect ( appConfig . load ( ) ) . rejects . toThrow ( 'Missing or invalid keys in app.config.yaml:' )
1150+ } )
1151+
1152+ test ( 'database configuration validation - valid' , async ( ) => {
1153+ const validConfig = {
1154+ application : {
1155+ runtimeManifest : {
1156+ database : {
1157+ 'auto-provision' : true ,
1158+ region : 'apac'
1159+ } ,
1160+ packages : {
1161+ 'my-app' : {
1162+ actions : {
1163+ hello : {
1164+ function : 'hello.js'
1165+ }
1166+ }
1167+ }
1168+ }
1169+ }
1170+ }
1171+ }
1172+ const validation = await appConfig . validate ( validConfig )
1173+ expect ( validation . valid ) . toBe ( true )
1174+ expect ( validation . errors ) . toBe ( null )
1175+ } )
1176+
1177+ test ( 'invalid database configuration - invalid auto-provision type' , async ( ) => {
1178+ global . fakeFileSystem . addJson ( {
1179+ '/package.json' : '{"name": "test-app", "version": "1.0.0"}' ,
1180+ '/app.config.yaml' : `
1181+ application:
1182+ runtimeManifest:
1183+ database:
1184+ auto-provision: 'invalid'
1185+ region: 'amer'
1186+ packages:
1187+ my-app-package:
1188+ actions:
1189+ action:
1190+ function: 'actions/hello.js'
1191+ web: true
1192+ `
1193+ } )
1194+ await expect ( appConfig . load ( { } ) ) . rejects . toThrow ( 'must be boolean' )
1195+ } )
1196+
1197+ test ( 'invalid database configuration - invalid region' , async ( ) => {
1198+ global . fakeFileSystem . addJson ( {
1199+ '/package.json' : '{"name": "test-app", "version": "1.0.0"}' ,
1200+ '/app.config.yaml' : `
1201+ application:
1202+ runtimeManifest:
1203+ database:
1204+ auto-provision: true
1205+ region: 'invalid-region'
1206+ packages:
1207+ my-app-package:
1208+ actions:
1209+ action:
1210+ function: 'actions/hello.js'
1211+ web: true
1212+ `
1213+ } )
1214+ await expect ( appConfig . load ( { } ) ) . rejects . toThrow ( 'must be equal to one of the allowed values' )
1215+ } )
1216+ } )
0 commit comments