Skip to content

getUserData never hits 'User not found' #25

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

Closed
cpsubrian opened this issue Apr 18, 2017 · 5 comments
Closed

getUserData never hits 'User not found' #25

cpsubrian opened this issue Apr 18, 2017 · 5 comments
Labels

Comments

@cpsubrian
Copy link
Contributor

In getUserData, my app never hits the 'User not found' error. The reason is because, in my results, total is the string "0", not the integer 0. See https://github.com/feathersjs/feathers-authentication-management/blob/master/src/helpers.js#L66

Is this something weird going on in my feather app or is this normal, and the code here should be updated to use an == or manually test both types?

Sample result for empty users query:

{ total: '0', limit: 10, skip: 0, data: [] }
@eddyystop
Copy link
Collaborator

getUserData is a helper function used by the functions exposed by the service. Which service action are you calling which results in getUserData being called?

If you are calling it directly, how are you doing so?

@cpsubrian
Copy link
Contributor Author

I'm well aware its a helper function 😄, I traced my problem to helpers.js after all. I'm triggering a 'resendVerifySignup' in my test suite. I traced this through to the user service query that results in the above data (total === '0'). I'm working on tracing through how the total gets to be a string in the first place, but I expect to find it somewhere in feathers core.

it('fails to resendVerifySignup on a non-existent user', () => {
  return Promise.resolve()
    .then(() => {
      return app.service(options.path).create({
        action: 'resendVerifySignup',
        value: {
          email: '[email protected]'
        }
      })
    })
    .then(() => {
      throw new Error('There should be an error, not a result')
    })
    .catch((err) => {
      expect(err.code).toBe(400)
      expect(err.message).toBe('User not found.')
    })
})

@cpsubrian
Copy link
Contributor Author

Not sure if I'm taking the docs too literally, but they also show total as a string: https://legacy.docs.feathersjs.com/databases/pagination.html

{
  "total": "<total number of records>",
  "limit": "<max number of items per page>",
  "skip": "<number of skipped items (offset)>",
  "data": [/* data */]
}

@eddyystop
Copy link
Collaborator

eddyystop commented Apr 19, 2017

Yes, I think that's a bit too literal.

I've never heard of hook.result.total being a string. I don't refer to it much myself though.

It would be fortunate if you can reproduce this consistently. I also think this occurs outside this repo.

I await your conclusions with baited breath. ;)

@cpsubrian
Copy link
Contributor Author

It turns out the database adapter returns strings in count queries, so I'd say the problem doesn't lie in this module. Will file an issue over there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants