Skip to content
Snippets Groups Projects
Unverified Commit b4579adc authored by Felix C. Stegerman's avatar Felix C. Stegerman Committed by GitHub
Browse files

[crates] recent_downloads can be null (#5237)

* crates: recent_downloads can be null

* crates: add test for recent_downloads = null
parent cde82547
No related branches found
No related tags found
No related merge requests found
......@@ -9,7 +9,7 @@ const keywords = ['Rust']
const crateSchema = Joi.object({
crate: Joi.object({
downloads: nonNegativeInteger,
recent_downloads: nonNegativeInteger,
recent_downloads: nonNegativeInteger.allow(null),
max_version: Joi.string().required(),
}).required(),
versions: Joi.array()
......
......@@ -87,7 +87,7 @@ module.exports = class CratesDownloads extends BaseCratesService {
case 'dv':
return json.crate ? json.versions[0].downloads : json.version.downloads
case 'dr':
return json.crate.recent_downloads
return json.crate.recent_downloads || 0
default:
return json.crate ? json.crate.downloads : json.version.downloads
}
......
......@@ -37,6 +37,22 @@ t.create('recent downloads').get('/dr/libc.json').expectBadge({
message: isMetric,
})
t.create('recent downloads (null)')
.get('/dr/libc.json')
.intercept(nock =>
nock('https://crates.io')
.get('/api/v1/crates/libc')
.reply(200, {
crate: {
downloads: 42,
recent_downloads: null,
max_version: '0.2.71',
},
versions: [{ downloads: 42, license: 'MIT OR Apache-2.0' }],
})
)
.expectBadge({ label: 'recent downloads', message: '0' })
t.create('recent downloads (with version)')
.get('/dr/libc/0.2.31.json')
.expectBadge({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment