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

feat: sending a custom rdme user agent with all requests #436

Merged
merged 4 commits into from
Feb 2, 2022

Conversation

erunion
Copy link
Member

@erunion erunion commented Feb 2, 2022

🧰 Changes

Much to my surprise and chagrin we weren't already sending a custom rdme/(major).(minor).(patch) user agent with all API requests. This fixes that!

🧬 QA & Testing

I've slightly shuffled around the cleanHeaders and handleRes libraries we had in src/lib into this new fetch wrapper in src/lib/fetch. Anything that once loaded node-fetch now loads this (which in turn loads node-fetch).

I've also added some unit tests for this to make sure that user agents are getting sent, changed every command test that mocks calls to our API to mock that API call + the user agent, and also cleaned up a few command tests that didn't have any explicit assertions (they were just silently testing either the mocks would succeed or that the command wouldn't fail).

@erunion erunion added the enhancement New feature or request label Feb 2, 2022
"jest": true
},
"rules": {
"jest/expect-expect": [
Copy link
Member Author

Choose a reason for hiding this comment

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

All tests have explicit expect()s now so we don't need add these exclusions for nock.

@erunion erunion changed the title feat: sending a rdme user agent with all requests feat: sending a custom rdme user agent with all requests Feb 2, 2022
Copy link
Member

@kanadgupta kanadgupta left a comment

Choose a reason for hiding this comment

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

A couple of small notes but otherwise LGTM! The refactor is real nice 👏🏽

Also quite bummed we hadn't been adding the user agent until now 😞

Comment on lines +189 to +197
await expect(docs.run({ folder: './__tests__/__fixtures__/new-docs', key, version })).resolves.toStrictEqual([
{
slug: 'new-doc',
body: '\nBody\n',
category: '5ae122e10fdf4e39bb34db6f',
title: 'This is the document title',
lastUpdatedHash: 'a23046c1e9d8ab47f8875ae7c5e429cb95be1c48',
},
]);
Copy link
Member

Choose a reason for hiding this comment

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

ugh we really had these tests in so many places lol 😭

});
await expect(docs.run({ folder: './__tests__/__fixtures__/slug-docs', key, version })).resolves.toStrictEqual([
{
slug: 'marc-actually-wrote-a-test',
Copy link
Member

Choose a reason for hiding this comment

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

lmao @mjcuva

@@ -1,3 +1,4 @@
/* eslint-disable jest/no-conditional-expect */
Copy link
Member

Choose a reason for hiding this comment

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

Could we disable it for each line or is it affecting the whole file?

Copy link
Member Author

Choose a reason for hiding this comment

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

Every test in this one has a conditional expect unfortunately.

src/lib/fetch.js Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants