Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion schema/app.config.yaml.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@
"runtimeManifest": {
"type": "object",
"properties": {
"packages": { "$ref": "#/definitions/packages" }
"packages": { "$ref": "#/definitions/packages" },
"database": { "$ref": "#/definitions/database" }
},
"required": ["packages"]
},
Expand All @@ -109,6 +110,15 @@
},
"additionalProperties": false
},
"database": {
"type": "object",
"properties": {
"auto-provision": { "type": "boolean"},
"region": { "type": "string"}
},
"required": ["auto-provision"],
"additionalProperties": false
},
"package": {
"type": "object",
"properties": {
Expand Down
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,9 @@ async function buildSingleConfig (configName, singleUserConfig, commonConfig, in
if (singleUserConfig.events) {
config.events = { ...singleUserConfig.events }
}
if (manifest && manifest.database) {
config.database = { ...manifest.database }
}
if (commonConfig?.aio?.project) {
config.project = commonConfig.aio.project
}
Expand Down
20 changes: 20 additions & 0 deletions test/__fixtures__/app-with-database/app.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
application:
actions: 'myactions'
runtimeManifest:
database:
auto-provision: true
region: 'emea'
packages:
my-app-package:
license: 'Apache-2.0'
actions:
action:
function: 'myactions/action.js'
web: 'yes'
runtime: 'nodejs:14'
inputs:
LOG_LEVEL: 'debug'
annotations:
final: true
require-adobe-auth: true
web: 'web-src'
10 changes: 10 additions & 0 deletions test/__fixtures__/app-with-database/myactions/action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Main action function
* @param {object} params - Action parameters
* @returns {object} Response object
*/
function main (params) {
return { msg: 'Hello world with database!' }
}

module.exports.main = main
7 changes: 7 additions & 0 deletions test/__fixtures__/app-with-database/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "app-with-database",
"version": "1.0.0",
"scripts": {
"test": "echo test"
}
}
9 changes: 9 additions & 0 deletions test/__fixtures__/app-with-database/web-src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>App with Database</title>
</head>
<body>
<h1>Hello from App with Database!</h1>
</body>
</html>
79 changes: 79 additions & 0 deletions test/data-mocks/config-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,73 @@ const applicationSingleConfig = {
}
}

const appWithDatabaseActionsFolder = winCompat(`${root}myactions`)
const applicationWithDatabaseSingleConfig = {
application: {
app: {
hasBackend: true,
hasFrontend: true,
dist: winCompat(`${root}dist/application`),
defaultHostname: 'adobeio-static.net',
hostname: 'mydomain.test',
htmlCacheDuration: '60',
jsCacheDuration: '60',
cssCacheDuration: '60',
imageCacheDuration: '60'
},
ow,
s3: {
credsCacheFile: winCompat(`${root}.aws.tmp.creds.json`)
},
web: {
src: winCompat(`${root}web-src`),
injectedConfig: winCompat(`${root}web-src/src/config.json`),
distDev: winCompat(`${root}dist/application/web-dev`),
distProd: winCompat(`${root}dist/application/web-prod`)
},
manifest: {
src: 'manifest.yml',
full: {
packages: {
'my-app-package': {
license: 'Apache-2.0',
actions: {
action: {
function: winCompat(`${appWithDatabaseActionsFolder}/action.js`),
web: 'yes',
runtime: 'nodejs:14',
inputs: {
LOG_LEVEL: 'debug'
},
annotations: {
final: true,
'require-adobe-auth': true
}
}
}
}
},
database: {
'auto-provision': true,
region: 'emea'
}
},
packagePlaceholder: '__APP_PACKAGE__',
package: undefined
},
actions: {
src: appWithDatabaseActionsFolder,
dist: winCompat(`${root}dist/application/actions`)
},
tests: {
e2e: winCompat(`${root}e2e`),
unit: winCompat(`${root}test`)
},
root: `${root}`,
name: 'application'
}
}

const legacyManifest = fullFakeRuntimeManifest(appActionsFolder, '__APP_PACKAGE__')
const applicationLegacyConfig = {
application: {
Expand Down Expand Up @@ -362,6 +429,18 @@ const expectedConfigs = {
},
root
},
'app-with-database': {
all: { ...applicationWithDatabaseSingleConfig },
implements: [
'application'
],
includeIndex: appIncludeIndex,
packagejson: {
version: '1.0.0',
name: 'app-with-database'
},
root
},
'app-exc-nui': {
all: { ...excSingleConfig, ...nuiSingleConfig, ...applicationSingleConfig },
implements: [
Expand Down
129 changes: 129 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ describe('load config', () => {
expect(config).toEqual(mockConfig)
})

test('standalone app config with database', async () => {
global.loadFixtureApp('app-with-database')
config = await appConfig.load()
expect(config.all.application.database).toEqual({
'auto-provision': true,
region: 'emea'
})
expect(config.all.application.app.hasBackend).toBe(true)
expect(config.all.application.app.hasFrontend).toBe(true)
})

test('not in an app', async () => {
global.loadFixtureApp('not-in-app')
await expect(appConfig.load()).rejects.toThrow(new Error('ENOENT: no such file or directory, open \'package.json\''))
Expand Down Expand Up @@ -1064,3 +1075,121 @@ describe('coalesce config', () => {
expect(coalesced.includeIndex['application.runtimeManifest.packages.my-app-package.actions.action.function']).toEqual({ file: 'app/myactions/action.config.yaml', key: 'function' })
})
})

describe('database config', () => {
beforeEach(async () => {
mockAIOConfig.get.mockImplementation(k => global.fakeConfig.tvm)
process.chdir('/')
global.fakeFileSystem.clear()
libEnv.getCliEnv.mockReturnValue('prod')
})

test('valid database configuration', async () => {
global.fakeFileSystem.addJson({
'/package.json': '{"name": "test-app", "version": "1.0.0"}',
'/app.config.yaml': `
application:
runtimeManifest:
database:
auto-provision: true
region: 'emea'
packages:
my-app-package:
actions:
action:
function: 'actions/hello.js'
web: true
`
})
const config = await appConfig.load()
expect(config.all.application.database).toEqual({
'auto-provision': true,
region: 'emea'
})
})

test('database configuration with auto-provision true', async () => {
global.fakeFileSystem.addJson({
'/package.json': '{"name": "test-app", "version": "1.0.0"}',
'/app.config.yaml': `
application:
runtimeManifest:
database:
auto-provision: true
packages:
my-app-package:
actions:
action:
function: 'actions/hello.js'
web: true
`
})
const config = await appConfig.load()
expect(config.all.application.database).toEqual({
'auto-provision': true
})
})

test('database configuration with empty fields', async () => {
global.fakeFileSystem.addJson({
'/package.json': '{"name": "test-app", "version": "1.0.0"}',
'/app.config.yaml': `
application:
runtimeManifest:
database: {}
packages:
my-app-package:
actions:
action:
function: 'actions/hello.js'
web: true
`
})
await expect(appConfig.load()).rejects.toThrow('Missing or invalid keys in app.config.yaml:')
})

test('database configuration validation - valid', async () => {
const validConfig = {
application: {
runtimeManifest: {
database: {
'auto-provision': true,
region: 'apac'
},
packages: {
'my-app': {
actions: {
hello: {
function: 'hello.js'
}
}
}
}
}
}
}
const validation = await appConfig.validate(validConfig)
expect(validation.valid).toBe(true)
expect(validation.errors).toBe(null)
})

test('invalid database configuration - invalid auto-provision type', async () => {
global.fakeFileSystem.addJson({
'/package.json': '{"name": "test-app", "version": "1.0.0"}',
'/app.config.yaml': `
application:
runtimeManifest:
database:
auto-provision: 'invalid'
region: 'amer'
packages:
my-app-package:
actions:
action:
function: 'actions/hello.js'
web: true
`
})
await expect(appConfig.load({})).rejects.toThrow('must be boolean')
})
})