diff --git a/services/symfony/symfony-insight-grade.tester.js b/services/symfony/symfony-insight-grade.tester.js index 678e4ab7c5..6b53c2d2a8 100644 --- a/services/symfony/symfony-insight-grade.tester.js +++ b/services/symfony/symfony-insight-grade.tester.js @@ -2,10 +2,10 @@ const Joi = require('@hapi/joi') const t = (module.exports = require('../tester').createServiceTester()) -const { sampleProjectUuid, checkShouldSkip } = require('./symfony-test-helpers') +const { sampleProjectUuid, noSymfonyToken } = require('./symfony-test-helpers') t.create('valid project grade') - .skipWhen(checkShouldSkip) + .skipWhen(noSymfonyToken) .get(`/${sampleProjectUuid}.json`) .timeout(15000) .expectBadge({ @@ -20,7 +20,7 @@ t.create('valid project grade') }) t.create('nonexistent project') - .skipWhen(checkShouldSkip) + .skipWhen(noSymfonyToken) .get('/45afb680-d4e6-4e66-93ea-bcfa79eb8a88.json') .expectBadge({ label: 'symfony insight', diff --git a/services/symfony/symfony-insight-stars.tester.js b/services/symfony/symfony-insight-stars.tester.js index 8d77105981..7bc4162ae7 100644 --- a/services/symfony/symfony-insight-stars.tester.js +++ b/services/symfony/symfony-insight-stars.tester.js @@ -2,10 +2,10 @@ const t = (module.exports = require('../tester').createServiceTester()) const { withRegex } = require('../test-validators') -const { sampleProjectUuid, checkShouldSkip } = require('./symfony-test-helpers') +const { sampleProjectUuid, noSymfonyToken } = require('./symfony-test-helpers') t.create('valid project stars') - .skipWhen(checkShouldSkip) + .skipWhen(noSymfonyToken) .get(`/${sampleProjectUuid}.json`) .timeout(15000) .expectBadge({ @@ -16,7 +16,7 @@ t.create('valid project stars') }) t.create('stars: nonexistent project') - .skipWhen(checkShouldSkip) + .skipWhen(noSymfonyToken) .get('/abc.json') .expectBadge({ label: 'symfony insight', diff --git a/services/symfony/symfony-insight-violations.tester.js b/services/symfony/symfony-insight-violations.tester.js index 38cdbdb0b2..5a053a44bf 100644 --- a/services/symfony/symfony-insight-violations.tester.js +++ b/services/symfony/symfony-insight-violations.tester.js @@ -2,10 +2,10 @@ const t = (module.exports = require('../tester').createServiceTester()) const { withRegex } = require('../test-validators') -const { sampleProjectUuid, checkShouldSkip } = require('./symfony-test-helpers') +const { sampleProjectUuid, noSymfonyToken } = require('./symfony-test-helpers') t.create('valid project violations') - .skipWhen(checkShouldSkip) + .skipWhen(noSymfonyToken) .get(`/${sampleProjectUuid}.json`) .timeout(15000) .expectBadge({ diff --git a/services/symfony/symfony-test-helpers.js b/services/symfony/symfony-test-helpers.js index 1f9bd0f670..f5d544beef 100644 --- a/services/symfony/symfony-test-helpers.js +++ b/services/symfony/symfony-test-helpers.js @@ -1,7 +1,5 @@ 'use strict' -const runnerConfig = require('config').util.toObject() - const sampleProjectUuid = '45afb680-d4e6-4e66-93ea-bcfa79eb8a87' function createMockResponse({ status = 'finished', grade, violations }) { @@ -88,17 +86,9 @@ const config = { }, } -function checkShouldSkip() { - const noToken = - !runnerConfig.private.sl_insight_userUuid || - !runnerConfig.private.sl_insight_apiToken - if (noToken) { - console.warn( - 'No Symfony credentials configured. Service tests will be skipped. Add credentials in local.yml to run these tests.' - ) - } - return noToken -} +const { noToken } = require('../test-helpers') +const { SymfonyInsightBase } = require('./symfony-insight-base') +const noSymfonyToken = noToken(SymfonyInsightBase) module.exports = { sampleProjectUuid, @@ -117,5 +107,5 @@ module.exports = { user, token, config, - checkShouldSkip, + noSymfonyToken, } diff --git a/services/test-helpers.js b/services/test-helpers.js index 656803b2d7..aa8edee4f6 100644 --- a/services/test-helpers.js +++ b/services/test-helpers.js @@ -2,6 +2,7 @@ const nock = require('nock') const request = require('request') +const runnerConfig = require('config').util.toObject() const { promisify } = require('../core/base-service/legacy-request-handler') function cleanUpNockAfterEach() { @@ -13,12 +14,31 @@ function cleanUpNockAfterEach() { }) } +function noToken(serviceClass) { + let hasLogged = false + return () => { + const userKey = serviceClass.auth.userKey + const passKey = serviceClass.auth.passKey + const noToken = + (userKey && !runnerConfig.private[userKey]) || + (passKey && !runnerConfig.private[passKey]) + if (noToken && !hasLogged) { + console.warn( + `${serviceClass.name}: no credentials configured, tests for this service will be skipped. Add credentials in local.yml to run them.` + ) + hasLogged = true + } + return noToken + } +} + const sendAndCacheRequest = promisify(request) const defaultContext = { sendAndCacheRequest } module.exports = { cleanUpNockAfterEach, + noToken, sendAndCacheRequest, defaultContext, } diff --git a/services/twitch/twitch.tester.js b/services/twitch/twitch.tester.js index 532507fd3b..54d8cadb45 100644 --- a/services/twitch/twitch.tester.js +++ b/services/twitch/twitch.tester.js @@ -1,29 +1,18 @@ 'use strict' const Joi = require('@hapi/joi') -const runnerConfig = require('config').util.toObject() const { ServiceTester } = require('../tester') +const { noToken } = require('../test-helpers') +const noTwitchToken = noToken(require('./twitch.service')) const t = (module.exports = new ServiceTester({ id: 'twitch', title: 'Twitch', })) -function checkShouldSkip() { - const noToken = - !runnerConfig.private.twitch_client_id || - !runnerConfig.private.twitch_client_secret - if (noToken) { - console.warn( - 'No Twitch client credentials configured. Service tests will be skipped. Add credentials in local.yml to run these tests.' - ) - } - return noToken -} - // the first request would take longer since we need to wait for a token t.create('Status of andyonthewings') - .skipWhen(checkShouldSkip) + .skipWhen(noTwitchToken) .get('/status/andyonthewings.json') .expectBadge({ label: 'twitch', @@ -33,7 +22,7 @@ t.create('Status of andyonthewings') // the second request should take shorter time since we can reuse the previous token t.create('Status of noopkat') - .skipWhen(checkShouldSkip) + .skipWhen(noTwitchToken) .get('/status/noopkat.json') .expectBadge({ label: 'twitch', diff --git a/services/wheelmap/wheelmap.tester.js b/services/wheelmap/wheelmap.tester.js index 03dcf018e2..1a618029fd 100644 --- a/services/wheelmap/wheelmap.tester.js +++ b/services/wheelmap/wheelmap.tester.js @@ -1,20 +1,11 @@ 'use strict' -const config = require('config').util.toObject() const t = (module.exports = require('../tester').createServiceTester()) - -function checkShouldSkip() { - const noToken = !config.private.wheelmap_token - if (noToken) { - console.warn( - 'No Wheelmap token configured. Service tests will be skipped. Add a token in local.yml to run these tests.' - ) - } - return noToken -} +const { noToken } = require('../test-helpers') +const noWheelmapToken = noToken(require('./wheelmap.service')) t.create('node with accessibility') - .skipWhen(checkShouldSkip) + .skipWhen(noWheelmapToken) .get('/26699541.json') .timeout(7500) .expectBadge({ @@ -24,7 +15,7 @@ t.create('node with accessibility') }) t.create('node with limited accessibility') - .skipWhen(checkShouldSkip) + .skipWhen(noWheelmapToken) .get('/2034868974.json') .timeout(7500) .expectBadge({ @@ -34,7 +25,7 @@ t.create('node with limited accessibility') }) t.create('node without accessibility') - .skipWhen(checkShouldSkip) + .skipWhen(noWheelmapToken) .get('/-147495158.json') .timeout(7500) .expectBadge({ @@ -44,7 +35,7 @@ t.create('node without accessibility') }) t.create('node not found') - .skipWhen(checkShouldSkip) + .skipWhen(noWheelmapToken) .get('/0.json') .timeout(7500) .expectBadge({