Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add [CratesUserDownloads] service and tester #10619

Merged
merged 6 commits into from
Oct 20, 2024

Conversation

jNullj
Copy link
Collaborator

@jNullj jNullj commented Oct 17, 2024

This pull request adds the CratesUserDownloads service and tester files.

The CratesUserDownloads service fetches data from the crates.io API to show the total downloads for a user.
It also includes tests for the service.

Added BaseCratesUserService for api route for users.

Solves #10614.

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

as requested by badges#10614
@jNullj jNullj changed the title Add CratesUserDownloads service and tester Add [CratesUserDownloads] service and tester Oct 17, 2024
@jNullj jNullj added service-badge New or updated service badge javascript [dependabot only] Pull requests that update Javascript packages labels Oct 17, 2024
Copy link
Contributor

github-actions bot commented Oct 17, 2024

Messages
📖 ✨ Thanks for your contribution to Shields, @jNullj!

Generated by 🚫 dangerJS against 7e64911

Copy link
Contributor

🚀 Updated review app: https://pr-10619-badges-shields.fly.dev

Copy link
Member

@chris48s chris48s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Couple of minor point, but good stuff

name: 'userId',
example: '3027',
description:
'The user ID can be found using https://crates.io/api/v1/users/{username}',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This renders as a link in the docs, but following it doesn't take you anywhere useful. Can we put it in `backticks` so it renders a <code> block instead of a link

Copy link
Collaborator Author

@jNullj jNullj Oct 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, it looks better with code block
Made changes at 2982c8f

.get('/udt/3027.json')
.expectBadge({ label: 'downloads', message: isMetric })

// we can not test for id not linked to user as it returns 0 downloads
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reckon we should put in a test case for a non-existant user id anyway, .expectBadge({ label: 'downloads', message: '0' }) in the assertion and explain in a comment that this API returns {"total_downloads": 0} with a 200 OK instead of a 404 response for a not found user id.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the test with 230c79a.
I realized they use int 32 for userid so i picked 2^32 as its the last id which has the least chance of getting taken.

userid for API usage is int32, therefor to minimize chance of user taking the id used the max value for int32 is used.
@jNullj jNullj requested a review from chris48s October 18, 2024 09:39
Copy link
Member

@PyvesB PyvesB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No further comments, let's get this merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
javascript [dependabot only] Pull requests that update Javascript packages service-badge New or updated service badge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants