1
0
mirror of https://github.com/badges/shields.git synced 2025-04-18 19:44:04 +03:00
shields/services/crates/crates-user-downloads.tester.js
jNullj 66631524c5
Add [CratesUserDownloads] service and tester (#10619)
* add jsdoc for crates fetch func

* add BaseCratesUserService for user stats api route

part of solution for #10614

* Add CratesUserDownloads service and tester

This commit adds the CratesUserDownloads service and tester files. The CratesUserDownloads service shows the user total downloads at Crates.io.

as requested by #10614

* render userid in code block

* add non-exsistent user CratesUserDownloads test

userid for API usage is int32, therefor to minimize chance of user taking the id used the max value for int32 is used.

* fixed typo
2024-10-20 20:03:54 +00:00

17 lines
686 B
JavaScript

import { isMetric } from '../test-validators.js'
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()
t.create('total user downloads')
.get('/udt/3027.json')
.expectBadge({ label: 'downloads', message: isMetric })
// non-existent user returns 0 downloads with 200 OK status code rather than 404.
t.create('total user downloads (user not found)')
.get('/udt/2147483647.json') // 2147483647 is the maximum valid user id as API uses i32
.expectBadge({ label: 'downloads', message: '0' })
t.create('total user downloads (invalid)')
.get('/udt/999999999999999999999999.json')
.expectBadge({ label: 'crates.io', message: 'invalid' })