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

Consolidate [NpmDownloads] into one service #3318

Merged
merged 1 commit into from
Apr 16, 2019

Conversation

paulmelnikow
Copy link
Member

This moves the four npm download services into a single class, in line with #3174, and other service implementations we've written in the last couple months.

  1. Change the suffixes from /m to /month for consistency.
  2. Add tests of one of the intervals besides total.
  3. Rewrite mocked service tests as unit tests.
  4. Use (and work with) the intervalMap pattern that I think @calebcartwright started us using.

This moves the four npm download services into a single class, in line with #3174, and other service implementations we've written in the last couple months.
@paulmelnikow paulmelnikow added the service-badge New or updated service badge label Apr 16, 2019
@shields-ci
Copy link

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

Generated by 🚫 dangerJS against f72daa1

return this.constructor.render({ downloads })
}
async handle({ interval, scope, packageName }) {
const { query, schema, transform } = intervalMap[interval]
Copy link
Member Author

Choose a reason for hiding this comment

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

I like using destructuring here. It makes this code particularly readable and I think a bit less error prone.

Copy link
Member

Choose a reason for hiding this comment

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

👍 I like this a lot too

dm: {
query: 'point/last-month',
schema: pointResponseSchema,
transform: json => json.downloads,
Copy link
Member Author

Choose a reason for hiding this comment

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

A little bit of repetition here, though it helps with clarity.

}
}
// For testing.
static get _intervalMap() {
Copy link
Member

Choose a reason for hiding this comment

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

Good idea! This makes things easy to test without having to define (and unnecessarily call) a class level render/transform function

@paulmelnikow paulmelnikow merged commit b79d195 into master Apr 16, 2019
@paulmelnikow paulmelnikow deleted the refactor-npm-downloads branch April 16, 2019 23:18
@shields-deployment
Copy link

This pull request was merged to master branch. This change is now waiting for deployment, which will usually happen within a few days. Stay tuned by joining our #ops channel on Discord!

After deployment, changes are copied to gh-pages branch:

paulmelnikow added a commit that referenced this pull request Apr 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
service-badge New or updated service badge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants