checkCustomIntegrationConfiguration moved to config.js + tests
This commit is contained in:
@@ -108,25 +108,10 @@ function loadTesters() {
|
||||
.map(path => require(path))
|
||||
}
|
||||
|
||||
function checkCustomIntegrationConfiguration(config, serviceClasses) {
|
||||
const serviceNames = new Set(
|
||||
serviceClasses.map(serviceClass => serviceClass.name)
|
||||
)
|
||||
const redundantConfigurations = Object.keys(config.public.integrations)
|
||||
.filter(configName => configName !== 'default')
|
||||
.filter(configName => !serviceNames.has(configName))
|
||||
if (redundantConfigurations.length) {
|
||||
throw new Error(
|
||||
`Custom configurations found without a corresponding service: ${redundantConfigurations}`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
InvalidService,
|
||||
loadServiceClasses,
|
||||
checkNames,
|
||||
collectDefinitions,
|
||||
loadTesters,
|
||||
checkCustomIntegrationConfiguration,
|
||||
}
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
'use strict'
|
||||
const deepmerge = require('deepmerge')
|
||||
|
||||
class RedundantCustomConfiguration extends Error {
|
||||
constructor(message) {
|
||||
super(message)
|
||||
this.name = 'RedundantCustomConfiguration'
|
||||
}
|
||||
}
|
||||
|
||||
function merge(_default, custom) {
|
||||
return deepmerge(_default, custom, {
|
||||
arrayMerge: function(destinationArray, sourceArray, options) {
|
||||
@@ -9,6 +16,22 @@ function merge(_default, custom) {
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
merge,
|
||||
function checkCustomIntegrationConfiguration(config, serviceClasses) {
|
||||
const serviceNames = new Set(
|
||||
serviceClasses.map(serviceClass => serviceClass.name)
|
||||
)
|
||||
const redundantConfigurations = Object.keys(config.public.integrations)
|
||||
.filter(configName => configName !== 'default')
|
||||
.filter(configName => !serviceNames.has(configName))
|
||||
if (redundantConfigurations.length) {
|
||||
throw new RedundantCustomConfiguration(
|
||||
`Custom configurations found without a corresponding service: ${redundantConfigurations}`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
RedundantCustomConfiguration,
|
||||
merge,
|
||||
checkCustomIntegrationConfiguration,
|
||||
}
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
'use strict'
|
||||
|
||||
const { test, given } = require('sazerac')
|
||||
const { merge } = require('./config')
|
||||
const { expect } = require('chai')
|
||||
const {
|
||||
RedundantCustomConfiguration,
|
||||
merge,
|
||||
checkCustomIntegrationConfiguration,
|
||||
} = require('./config')
|
||||
|
||||
describe('configuration', function() {
|
||||
test(merge, function() {
|
||||
@@ -24,4 +29,33 @@ describe('configuration', function() {
|
||||
.describe('overrides array')
|
||||
.expect({ a: [5, 6] })
|
||||
})
|
||||
|
||||
describe('checkCustomIntegrationConfiguration function', function() {
|
||||
it('accept default configuration', function() {
|
||||
const config = { public: { integrations: { default: {} } } }
|
||||
const serviceClasses = [{ name: 'SomeService' }]
|
||||
|
||||
expect(() =>
|
||||
checkCustomIntegrationConfiguration(config, serviceClasses)
|
||||
).not.throw()
|
||||
})
|
||||
|
||||
it('accept a configuration for an existing service', function() {
|
||||
const config = { public: { integrations: { SomeService: {} } } }
|
||||
const serviceClasses = [{ name: 'SomeService' }]
|
||||
|
||||
expect(() =>
|
||||
checkCustomIntegrationConfiguration(config, serviceClasses)
|
||||
).not.throw()
|
||||
})
|
||||
|
||||
it('throws an error if a custom config does not have a corresponding service', function() {
|
||||
const config = { public: { integrations: { UnknownService: {} } } }
|
||||
const serviceClasses = [{ name: 'KnownService' }]
|
||||
|
||||
expect(() =>
|
||||
checkCustomIntegrationConfiguration(config, serviceClasses)
|
||||
).to.throw(RedundantCustomConfiguration)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -10,10 +10,7 @@ const Camp = require('camp')
|
||||
const makeBadge = require('../../gh-badges/lib/make-badge')
|
||||
const GithubConstellation = require('../../services/github/github-constellation')
|
||||
const suggest = require('../../services/suggest')
|
||||
const {
|
||||
loadServiceClasses,
|
||||
checkCustomIntegrationConfiguration,
|
||||
} = require('../base-service/loader')
|
||||
const { loadServiceClasses } = require('../base-service/loader')
|
||||
const { makeSend } = require('../base-service/legacy-result-sender')
|
||||
const {
|
||||
handleRequest,
|
||||
@@ -21,7 +18,7 @@ const {
|
||||
} = require('../base-service/legacy-request-handler')
|
||||
const { clearRegularUpdateCache } = require('../legacy/regular-update')
|
||||
const { rasterRedirectUrl } = require('../badge-urls/make-badge-url')
|
||||
const { merge } = require('./config')
|
||||
const { merge, checkCustomIntegrationConfiguration } = require('./config')
|
||||
const log = require('./log')
|
||||
const sysMonitor = require('./monitor')
|
||||
const PrometheusMetrics = require('./prometheus-metrics')
|
||||
|
||||
Reference in New Issue
Block a user