Files
shields/services/sonar/sonar-violations.spec.js
Caleb Cartwright 700b61e16b Refactor [Sonar] (#3189)
* refactor(sonar)

* refactor(sonarqube): creating separate services for SQ badges

* refactor(sonar): more sonar refactorings

* refactor(sonar): fixed duplicate service names from c/p

* refactor(sonar): finished violations service impl

* refactor(sonar): finished unit tests for violations service

* feat(sonar): violation badge updates

* refactor(sonar): finished doc. api density service

* feat(sonar): added quality gate service

* chore: sonar doc tweaks

* refactor(sonar): added redirector service

* refactor(sonar): added examples

* refactor(sonar): minor example updates

* refactor(sonar): added final tests

* chore(sonar): removed unneeded test spec file for base class

* refactor(sonar): updates based on PR feedback

* refactor(sonar): change query param to sonarVersion

* refactor(sonar): fixing query param issue

* refactor(sonar): fix test color for generic metric

* chore: fix lint/prettier issue

* chore(sonar): update query param name in examples

* refactor(sonar): make schema metric key required

* reactor(sonar): fix tests

* refactor(sonar): added more example listings

* refactor(sonar): minor style updates

* refactor(sonar): update examples

* refactor(Sonar): minor example tweaks
2019-04-15 17:03:57 -05:00

116 lines
3.4 KiB
JavaScript

'use strict'
const { test, given } = require('sazerac')
const { metric } = require('../text-formatters')
const SonarViolations = require('./sonar-violations.service')
describe('SonarViolations', function() {
test(SonarViolations.render, () => {
given({ metricName: 'violations', violations: 1003 }).expect({
message: metric(1003),
color: 'red',
})
given({ metricName: 'violations', violations: 0, format: 'short' }).expect({
message: '0',
color: 'brightgreen',
})
given({ metricName: 'violations', violations: 1 }).expect({
message: '1',
color: 'yellowgreen',
})
given({ metricName: 'violations', violations: 2 }).expect({
message: '2',
color: 'yellow',
})
given({ metricName: 'violations', violations: 3 }).expect({
message: '3',
color: 'orange',
})
given({ metricName: 'violations', violations: 4 }).expect({
message: '4',
color: 'orange',
})
given({ metricName: 'violations', violations: 5 }).expect({
message: '5',
color: 'red',
})
given({ metricName: 'blocker_violations', violations: 0 }).expect({
label: 'blocker violations',
message: '0',
color: 'brightgreen',
})
given({ metricName: 'blocker_violations', violations: 1 }).expect({
label: 'blocker violations',
message: '1',
color: 'red',
})
given({ metricName: 'critical_violations', violations: 0 }).expect({
label: 'critical violations',
message: '0',
color: 'brightgreen',
})
given({ metricName: 'critical_violations', violations: 2 }).expect({
label: 'critical violations',
message: '2',
color: 'orange',
})
given({ metricName: 'major_violations', violations: 0 }).expect({
label: 'major violations',
message: '0',
color: 'brightgreen',
})
given({ metricName: 'major_violations', violations: 3 }).expect({
label: 'major violations',
message: '3',
color: 'yellow',
})
given({ metricName: 'minor_violations', violations: 0 }).expect({
label: 'minor violations',
message: '0',
color: 'brightgreen',
})
given({ metricName: 'minor_violations', violations: 1 }).expect({
label: 'minor violations',
message: '1',
color: 'yellowgreen',
})
given({ metricName: 'info_violations', violations: 0 }).expect({
label: 'info violations',
message: '0',
color: 'brightgreen',
})
given({ metricName: 'info_violations', violations: 4 }).expect({
label: 'info violations',
message: '4',
color: 'green',
})
})
test(SonarViolations.renderLongViolationsBadge, () => {
given({ violations: 0 }).expect({
message: 0,
color: 'brightgreen',
})
given({ violations: 3, info_violations: 3 }).expect({
message: '3 info',
color: 'green',
})
given({ violations: 2, info_violations: 1, minor_violations: 1 }).expect({
message: '1 minor, 1 info',
color: 'yellowgreen',
})
given({ violations: 1, major_violations: 1 }).expect({
message: '1 major',
color: 'yellow',
})
given({ violations: 2, critical_violations: 2 }).expect({
message: '2 critical',
color: 'orange',
})
given({ violations: 6, info_violations: 5, blocker_violations: 1 }).expect({
message: '1 blocker, 5 info',
color: 'red',
})
})
})