diff --git a/services/symfony/symfony-insight-base.js b/services/symfony/symfony-insight-base.js index 91cb91b9f2..e521536216 100644 --- a/services/symfony/symfony-insight-base.js +++ b/services/symfony/symfony-insight-base.js @@ -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 diff --git a/services/symfony/symfony-insight-base.spec.js b/services/symfony/symfony-insight-base.spec.js new file mode 100644 index 0000000000..35baa343ee --- /dev/null +++ b/services/symfony/symfony-insight-base.spec.js @@ -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') + } + }) + }) +})