1
0
mirror of https://github.com/badges/shields.git synced 2025-12-01 18:37:54 +03:00

Refactor [SymfonyInsight] to new service model and rename (#2572)

Based on some discussion/feedback here, this PR now contains several changes:

* Renames the `Sensiolabs` badge/service content to `SymfonyInsight` to reflect the rebranding of that product/service
* Refactors the original service to the new service model (using `BaseXmlService`)
* Updates the color scheme of the original/initial badge type (SymfonyInsight Grade) to more closely mirror the colors used by the vendor/service provider
* Adds a new badge type (violation counts/summary) 
* Adds both mocked and live tests (there were none before) for both the grade & violation badges using the new path `symfony/i` as well as a couple tests for the old path `sensiolabs/i` to check for backwards compatibility

Refs #1358
This commit is contained in:
Caleb Cartwright
2019-01-06 23:28:45 -06:00
committed by Paul Melnikow
parent b32f6eab55
commit ca487ae086
4 changed files with 741 additions and 110 deletions

View File

@@ -0,0 +1,134 @@
'use strict'
const sinon = require('sinon')
const serverSecrets = require('../../lib/server-secrets')
function createMockResponse({ status = 'finished', grade, violations }) {
let response = `
<project>
<last-analysis>
<status><![CDATA[${status}]]></status>
${grade ? `<grade><![CDATA[${grade}]]></grade>` : ''}`
if (violations) {
response = `${response}<violations>`
violations.forEach(v => {
response = `${response}<violation severity="${v.severity}"></violation>`
})
response = `${response}</violations>`
}
return `${response}</last-analysis></project>`
}
const runningMockResponse = createMockResponse({
status: 'running',
})
const platinumMockResponse = createMockResponse({
grade: 'platinum',
})
const goldMockResponse = createMockResponse({
grade: 'gold',
})
const silverMockResponse = createMockResponse({
grade: 'silver',
})
const bronzeMockResponse = createMockResponse({
grade: 'bronze',
})
const noMedalMockResponse = createMockResponse({
grade: 'none',
})
const criticalViolation = createMockResponse({
violations: [
{
severity: 'critical',
},
],
})
const majorViolation = createMockResponse({
violations: [
{
severity: 'major',
},
],
})
const minorViolation = createMockResponse({
violations: [
{
severity: 'minor',
},
],
})
const infoViolation = createMockResponse({
violations: [
{
severity: 'info',
},
],
})
const multipleViolations = createMockResponse({
violations: [
{
severity: 'info',
},
{
severity: 'critical',
},
],
})
const mockSymfonyUser = 'admin'
const mockSymfonyToken = 'password'
const originalUuid = serverSecrets.sl_insight_userUuid
const originalApiToken = serverSecrets.sl_insight_apiToken
function setSymfonyInsightCredsToFalsy() {
serverSecrets['sl_insight_userUuid'] = undefined
serverSecrets['sl_insight_apiToken'] = undefined
}
function mockSymfonyInsightCreds() {
// ensure that the fields exists before attempting to stub
setSymfonyInsightCredsToFalsy()
sinon.stub(serverSecrets, 'sl_insight_userUuid').value(mockSymfonyUser)
sinon.stub(serverSecrets, 'sl_insight_apiToken').value(mockSymfonyToken)
}
function restore() {
sinon.restore()
serverSecrets['sl_insight_userUuid'] = originalUuid
serverSecrets['sl_insight_apiToken'] = originalApiToken
}
function prepLiveTest() {
// Since the service implementation will throw an error if the creds
// are missing, we need to ensure that creds are available for each test.
// In the case of the live tests we want to use the "real" creds if they
// exist otherwise we need to use the same stubbed creds as all the mocked tests.
if (!originalUuid) {
console.warn(
'No token provided, this test will mock Symfony Insight API responses.'
)
mockSymfonyInsightCreds()
}
}
module.exports = {
runningMockResponse,
platinumMockResponse,
goldMockResponse,
silverMockResponse,
bronzeMockResponse,
noMedalMockResponse,
mockSymfonyUser,
mockSymfonyToken,
mockSymfonyInsightCreds,
setSymfonyInsightCredsToFalsy,
restore,
realTokenExists: originalUuid,
prepLiveTest,
criticalViolation,
majorViolation,
minorViolation,
infoViolation,
multipleViolations,
}