Files
shields/services/snyk/snyk-vulnerability-github.tester.js
T
Pierre-Yves BandGitHub 25f8541e5b JSON format modernisation and _shields_test removal (#3272)
* Modernised JSON format and removed _shields_test style

* Added logoWidth and labelColor fields to JSON response

* Reinstated and updated comment

* Extended expectBadge to accept Joi schemas for all fields
2019-04-07 18:57:55 +01:00

99 lines
2.4 KiB
JavaScript

'use strict'
const Joi = require('joi')
const t = (module.exports = require('../tester').createServiceTester())
const {
twoVulnerabilitiesSvg,
zeroVulnerabilitiesSvg,
} = require('./snyk-test-helpers')
t.create('live: valid repo')
.get('/badges/shields.json')
.timeout(10000)
.expectBadge({
label: 'vulnerabilities',
message: Joi.number().required(),
})
t.create('live: non existent repo')
.get('/badges/not-real.json')
.timeout(10000)
.expectBadge({
label: 'vulnerabilities',
message: 'repo or manifest not found',
})
t.create('live: valid target manifest path')
.get('/badges/shields/gh-badges/package.json.json')
.timeout(10000)
.expectBadge({
label: 'vulnerabilities',
message: Joi.number().required(),
})
t.create('live: invalid target manifest path')
.get('/badges/shields/gh-badges/requirements.txt.json')
.timeout(10000)
.expectBadge({
label: 'vulnerabilities',
message: 'repo or manifest not found',
})
t.create('repo has no vulnerabilities')
.get('/badges/shields.json')
.intercept(nock =>
nock('https://snyk.io/test/github/badges/shields')
.get('/badge.svg')
.reply(200, zeroVulnerabilitiesSvg)
)
.expectBadge({
label: 'vulnerabilities',
message: '0',
color: 'brightgreen',
})
t.create('repo has vulnerabilities')
.get('/badges/shields.json')
.intercept(nock =>
nock('https://snyk.io/test/github/badges/shields')
.get('/badge.svg')
.reply(200, twoVulnerabilitiesSvg)
)
.expectBadge({
label: 'vulnerabilities',
message: '2',
color: 'red',
})
t.create('target manifest file has no vulnerabilities')
.get('/badges/shields/gh-badges/package.json.json')
.intercept(nock =>
nock('https://snyk.io/test/github/badges/shields')
.get('/badge.svg')
.query({
targetFile: 'gh-badges/package.json',
})
.reply(200, zeroVulnerabilitiesSvg)
)
.expectBadge({
label: 'vulnerabilities',
message: '0',
color: 'brightgreen',
})
t.create('target manifest file has vulnerabilities')
.get('/badges/shields/gh-badges/package.json.json')
.intercept(nock =>
nock('https://snyk.io/test/github/badges/shields')
.get('/badge.svg')
.query({
targetFile: 'gh-badges/package.json',
})
.reply(200, twoVulnerabilitiesSvg)
)
.expectBadge({
label: 'vulnerabilities',
message: '2',
color: 'red',
})