Skip to content

Commit

Permalink
add productDependencies config (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
moritzraho committed Jul 10, 2023
1 parent 545f091 commit a9c05c3
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 19 deletions.
19 changes: 16 additions & 3 deletions schema/app.config.yaml.schema.json
Expand Up @@ -5,7 +5,8 @@
"properties": {
"application": { "$ref": "#/definitions/application" },
"extensions": { "$ref": "#/definitions/extensions" },
"configSchema": { "$ref": "#/definitions/configSchema"}
"configSchema": { "$ref": "#/definitions/configSchema"},
"productDependencies": { "$ref": "#/definitions/productDependencies"}
},
"anyOf": [
{
Expand Down Expand Up @@ -201,7 +202,6 @@
},
"configSchema": {
"type": "array",
"minItems": 1,
"maxItems": 50,
"items": {
"type": "object",
Expand All @@ -217,6 +217,19 @@
"additionalProperties": false
}
},
"configSchemaValue": { "type": "string", "maxLength": 1000 }
"configSchemaValue": { "type": "string", "maxLength": 1000 },
"productDependencies": {
"type": "array",
"items": {
"type": "object",
"properties": {
"code": { "type": "string" },
"minVersion": { "type": "string", "pattern": "^[0-9]+.[0-9]+.[0-9]+$" },
"maxVersion": { "type": "string", "pattern": "^[0-9]+.[0-9]+.[0-9]+$" }
},
"required": ["code", "minVersion", "maxVersion"],
"additionalProperties": false
}
}
}
}
5 changes: 4 additions & 1 deletion src/index.js
Expand Up @@ -84,6 +84,8 @@ const cloneDeep = require('lodash.clonedeep')
* configSchema: { app.config.yaml configSchema field }
* aio: {...aioConfig...},
* packagejson: {...package.json...},
* configSchema: {...app.config.yaml configSchema field as is},
* productDependencies: {...app.config.yaml productDependencies field as is},
* all: {
* OPTIONAL:'application': {
* app: {
Expand Down Expand Up @@ -177,7 +179,8 @@ async function load (options = {}) {
throw new Error(`Couldn't find configuration in '${process.cwd()}', make sure to add at least one extension or a standalone app`)
}
return {
configSchema: appConfig?.configSchema,
configSchema: appConfig?.configSchema || [],
productDependencies: appConfig?.productDependencies || [],
all,
implements: impl, // e.g. 'dx/excshell/1', 'application'
// includeIndex keeps a map from config keys to files that includes them and the relative key in the file.
Expand Down
4 changes: 3 additions & 1 deletion test/data-mocks/config-loader.js
Expand Up @@ -450,6 +450,8 @@ module.exports = (appFixtureName, mockedAIOConfig, rewriteMockConfig = {}) => {
})
return {
...config,
aio: mockedAIOConfig
aio: mockedAIOConfig,
configSchema: config.configSchema || [],
productDependencies: config.productDependencies || []
}
}
147 changes: 133 additions & 14 deletions test/index.test.js
Expand Up @@ -518,6 +518,19 @@ application:
await expect(appConfig.load({})).resolves.toEqual(expect.objectContaining({ configSchema: [{ default: 'hello', enum: ['hello', 'hola', 'bonjour'], envKey: 'HELLO', secret: true, title: 'yo', type: 'string' }, { envKey: 'BYE', type: 'boolean' }] }))
})

test('valid no configSchema', async () => {
global.fakeFileSystem.addJson(
{
'/package.json': '{}',
'/app.config.yaml': `
application:
runtimeManifest: { packages: {}}
`
}
)
await expect(appConfig.load({})).resolves.toEqual(expect.objectContaining({ configSchema: [] }))
})

test('invalid schema: web.res-header instead of web.response-headers', async () => {
global.fakeFileSystem.addJson(
{
Expand Down Expand Up @@ -553,20 +566,6 @@ application:
await expect(appConfig.load({})).rejects.toThrow('"missingProperty": "packages"')
})

test('invalid schema: configSchema has no items', async () => {
global.fakeFileSystem.addJson(
{
'/package.json': '{}',
'/app.config.yaml': `
configSchema: []
application:
runtimeManifest: { packages: {}}
`
}
)
await expect(appConfig.load({})).rejects.toThrow('"message": "must NOT have fewer than 1 items"')
})

test('invalid schema: configSchema has an item without envKey', async () => {
global.fakeFileSystem.addJson(
{
Expand Down Expand Up @@ -629,6 +628,126 @@ application:
)
await expect(appConfig.load({})).rejects.toThrow('must be equal to one of the allowed values')
})

test('valid schema with productDependencies', async () => {
global.fakeFileSystem.addJson(
{
'/package.json': '{}',
'/app.config.yaml': `
productDependencies:
- code: 'somecode'
minVersion: '1.0.0'
maxVersion: '2.0.0'
- code: 'someOthercode'
minVersion: '1.0.0'
maxVersion: '3.0.0'
application:
runtimeManifest: { packages: {}}
`
}
)
await expect(appConfig.load({})).resolves.toEqual(expect.objectContaining({ productDependencies: [{ code: 'somecode', maxVersion: '2.0.0', minVersion: '1.0.0' }, { code: 'someOthercode', maxVersion: '3.0.0', minVersion: '1.0.0' }] }))
})

test('valid no productDependencies', async () => {
global.fakeFileSystem.addJson(
{
'/package.json': '{}',
'/app.config.yaml': `
application:
runtimeManifest: { packages: {}}
`
}
)
await expect(appConfig.load({})).resolves.toEqual(expect.objectContaining({ productDependencies: [] }))
})

test('valid productDependencies: no items', async () => {
global.fakeFileSystem.addJson(
{
'/package.json': '{}',
'/app.config.yaml': `
productDependencies: []
application:
runtimeManifest: { packages: {}}
`
}
)
await expect(appConfig.load({})).resolves.toEqual(expect.objectContaining({ productDependencies: [] }))
})

test('invalid productDependencies: missing minVersion', async () => {
global.fakeFileSystem.addJson(
{
'/package.json': '{}',
'/app.config.yaml': `
productDependencies:
- code: 'somecode'
minVersion: '1.0.0'
maxVersion: '2.0.0'
- code: 'someOthercode'
maxVersion: '3.0.0'
application:
runtimeManifest: { packages: {}}
`
}
)
await expect(appConfig.load({})).rejects.toThrow("must have required property 'minVersion'")
})

test('invalid productDependencies: missing maxVersion', async () => {
global.fakeFileSystem.addJson(
{
'/package.json': '{}',
'/app.config.yaml': `
productDependencies:
- code: 'somecode'
minVersion: '1.0.0'
maxVersion: '2.0.0'
- code: 'someOthercode'
minVersion: '3.0.0'
application:
runtimeManifest: { packages: {}}
`
}
)
await expect(appConfig.load({})).rejects.toThrow("must have required property 'maxVersion'")
})

test('invalid productDependencies: missing code', async () => {
global.fakeFileSystem.addJson(
{
'/package.json': '{}',
'/app.config.yaml': `
productDependencies:
-
minVersion: '1.0.0'
maxVersion: '2.0.0'
application:
runtimeManifest: { packages: {}}
`
}
)
await expect(appConfig.load({})).rejects.toThrow("must have required property 'code'")
})

test('invalid productDependencies: invalid extra field', async () => {
global.fakeFileSystem.addJson(
{
'/package.json': '{}',
'/app.config.yaml': `
productDependencies:
- code: somecode
minVersion: '1.0.0'
maxVersion: '2.0.0'
midVersion: 'field'
application:
runtimeManifest: { packages: {}}
`
}
)
await expect(appConfig.load({})).rejects.toThrow('must NOT have additional properties')
})
})

describe('validate config', () => {
Expand Down

0 comments on commit a9c05c3

Please sign in to comment.