The NuGet badge examples are straggling in all-badge-examples. Rather than move them as is, I thought it made more sense to refactor the services and see if they could be generated. I didn't take that on here; this is a straight rewrite of the badges. The old implementations were fairly difficult to follow. The new implementations are complicated too, though I hope much more readable. Though the NuGet behaviors could be consolidated into a single flag, I split `withTenant` and `withFeed` into separate flags, thinking naming the behaviors makes the implementations easier to understand. I defaulted these to true, thinking that really this is really a MyGet implementation which is generalized to NuGet. Though maybe it makes more sense to have the MyGet style as the default. Probably it doesn't matter much either way. I added a helper class ServiceUrlBuilder to construct the Shields service URL. It's useful in this complex case where the URL must be built up conditionally. This might be useful in a couple other places. I also wrote a new service to handle the Powershell badges. They've diverged a little bit from the Nuget v2. There's a bit of shared code which I factored out. If the XML Nuget APIs are more reliable, we could consider switching everything else over to them, though for now I would like to get this merged and get #2078 fixed. Fix #2078
55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
'use strict'
|
|
|
|
const Joi = require('joi')
|
|
const ServiceTester = require('../service-tester')
|
|
const {
|
|
isMetric,
|
|
isVPlusDottedVersionNClauses,
|
|
isVPlusDottedVersionNClausesWithOptionalSuffix,
|
|
} = require('../test-validators')
|
|
|
|
const t = new ServiceTester({
|
|
id: 'powershellgallery',
|
|
title: 'PowerShell Gallery',
|
|
})
|
|
module.exports = t
|
|
|
|
t.create('total downloads (valid)')
|
|
.get('/dt/ACMESharp.json')
|
|
.expectJSONTypes(
|
|
Joi.object().keys({
|
|
name: 'downloads',
|
|
value: isMetric,
|
|
})
|
|
)
|
|
|
|
t.create('total downloads (not found)')
|
|
.get('/dt/not-a-real-package.json')
|
|
.expectJSON({ name: 'downloads', value: 'not found' })
|
|
|
|
t.create('version (valid)')
|
|
.get('/v/ACMESharp.json')
|
|
.expectJSONTypes(
|
|
Joi.object().keys({
|
|
name: 'powershell gallery',
|
|
value: isVPlusDottedVersionNClauses,
|
|
})
|
|
)
|
|
|
|
t.create('version (not found)')
|
|
.get('/v/not-a-real-package.json')
|
|
.expectJSON({ name: 'powershell gallery', value: 'not found' })
|
|
|
|
t.create('version (pre) (valid)')
|
|
.get('/vpre/ACMESharp.json')
|
|
.expectJSONTypes(
|
|
Joi.object().keys({
|
|
name: 'powershell gallery',
|
|
value: isVPlusDottedVersionNClausesWithOptionalSuffix,
|
|
})
|
|
)
|
|
|
|
t.create('version (pre) (not found)')
|
|
.get('/vpre/not-a-real-package.json')
|
|
.expectJSON({ name: 'powershell gallery', value: 'not found' })
|