fix: SymfonyInsight transform (#4877)

Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
Caleb Cartwright
2020-04-08 14:59:42 -05:00
committed by GitHub
parent b2bb50234f
commit 642aac6408
2 changed files with 27 additions and 1 deletions

View File

@@ -1,7 +1,7 @@
'use strict'
const Joi = require('@hapi/joi')
const { BaseXmlService } = require('..')
const { BaseXmlService, NotFound } = require('..')
const violationSchema = Joi.object({
severity: Joi.equal('info', 'minor', 'major', 'critical').required(),
@@ -87,6 +87,11 @@ class SymfonyInsightBase extends BaseXmlService {
transform({ data }) {
const lastAnalysis = data.project['last-analysis']
if (!lastAnalysis) {
throw new NotFound({ prettyMessage: 'no analyses found' })
}
let numViolations = 0
let numCriticalViolations = 0
let numMajorViolations = 0

View File

@@ -0,0 +1,21 @@
'use strict'
const { expect } = require('chai')
const { SymfonyInsightBase } = require('./symfony-insight-base')
const { NotFound } = require('..')
describe('SymfonyInsightBase', function() {
context('transform()', function() {
it('throws NotFound error when there is no coverage data', function() {
try {
SymfonyInsightBase.prototype.transform({
data: { project: {} },
})
expect.fail('Expected to throw')
} catch (e) {
expect(e).to.be.an.instanceof(NotFound)
expect(e.prettyMessage).to.equal('no analyses found')
}
})
})
})