Refactor checkShouldSkip, affects [Twitch SymfonyInsight Wheelmap] (#4807)
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user