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

fix: quirks with version commands and config retrieval #423

Merged
merged 19 commits into from
Jan 11, 2022
Merged

Conversation

erunion
Copy link
Member

@erunion erunion commented Jan 9, 2022

🧰 Changes

While tinkering around with Typescript here I discovered a few quirks:

  • versions:delete would never properly alert you if your deletion failed, and our tests to check for this weren't actually testing it.
    • I've slightly refactored a few tests in this suite so they now always assert either a command resolution or rejection.
  • When retrieving config data out of the config Typescript didn't like how we're doing config.host so I've updated all config.* retrievals to use the preferrable .get() accessor.

🧬 QA & Testing

  • Tests pass?

@erunion erunion added the bug Something isn't working label Jan 9, 2022
@erunion erunion requested review from kanadgupta, a team, Dashron and julshotal and removed request for a team January 9, 2022 08:28
.delete(`/api/v1/version/${version}`)
.basicAuth({ user: key })
.reply(200)
.reply(200, { removed: true })
Copy link
Member Author

Choose a reason for hiding this comment

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

Added {removed: true} because that's what we return in our API and the handleRes handler was failing without this because .reply(200) by itself doesn't return JSON for res.json().

We should probably actually return a 204 No Content instead for these delete calls but 🤷

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.

Looking good, just a few test bed suggestions below!

__tests__/cmds/login.test.js Outdated Show resolved Hide resolved
__tests__/cmds/versions.test.js Outdated Show resolved Hide resolved
__tests__/cmds/versions.test.js Outdated Show resolved Hide resolved
@@ -15,28 +15,27 @@ describe('rdme login', () => {
});

it('should error if email is invalid', () => {
expect.assertions(1);
return expect(cmd.run({ project: 'subdomain', email: 'this-is-not-an-email' })).rejects.toThrow(
Copy link
Member

@kanadgupta kanadgupta Jan 11, 2022

Choose a reason for hiding this comment

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

I'm a little lukewarm on using toThrow when we can use toBe(new Error('msg')) since toThrow only checks for substrings in error messages (see docs)... but we can leave that as out-of-scope for this PR!

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've always had the worst trouble with toBe(new Error('msg')):

  ● rdme login › should error if no project provided

    expect(received).rejects.toBe(expected) // Object.is equality

    If it should pass with deep equality, replace "toBe" with "toStrictEqual"

    Expected: [Error: No project subdomain provided. Please use `--project`.]
    Received: serializes to the same string

      17 |
      18 |   it('should error if no project provided', () => {
    > 19 |     return expect(cmd.run({})).rejects.toBe(new Error('No project subdomain provided. Please use `--project`.'));
         |                                        ^
      20 |   });
      21 |
      22 |   it('should error if email is invalid', () => {

      at Object.toBe (node_modules/expect/build/index.js:285:22)
      at Object.<anonymous> (__tests__/cmds/login.test.js:19:40)

Copy link
Member

Choose a reason for hiding this comment

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

oh whooops sorry it definitely should be toStrictEqual, but I think that's the only issue there?

src/cmds/open.js Show resolved Hide resolved
src/cmds/login.js Show resolved Hide resolved
__tests__/cmds/versions.test.js Outdated Show resolved Hide resolved
__tests__/cmds/versions.test.js Outdated Show resolved Hide resolved
src/cmds/versions/update.js Show resolved Hide resolved
__tests__/cmds/versions.test.js Show resolved Hide resolved
@erunion
Copy link
Member Author

erunion commented Jan 11, 2022

@kanadgupta I pushed up a bunch of changes if you want to give this another look

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.

Sorry, I saw a few more places where we could be using toStrictEqual (assuming it works properly) and just noticed a few areas where we could enhance our tests... but other than that, LGTM!

__tests__/cmds/whoami.test.js Outdated Show resolved Hide resolved
__tests__/cmds/versions.test.js Outdated Show resolved Hide resolved
__tests__/cmds/versions.test.js Outdated Show resolved Hide resolved
__tests__/cmds/versions.test.js Outdated Show resolved Hide resolved
__tests__/cmds/versions.test.js Outdated Show resolved Hide resolved
__tests__/cmds/versions.test.js Outdated Show resolved Hide resolved
__tests__/cmds/login.test.js Outdated Show resolved Hide resolved
__tests__/cmds/login.test.js Outdated Show resolved Hide resolved
__tests__/cmds/login.test.js Outdated Show resolved Hide resolved
__tests__/cmds/login.test.js Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants