Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

πŸ› BUG: Unhandeled Promise Rejection in User tests. #204

Closed
khase opened this issue Sep 20, 2017 · 2 comments Β· Fixed by #625
Closed

πŸ› BUG: Unhandeled Promise Rejection in User tests. #204

khase opened this issue Sep 20, 2017 · 2 comments Β· Fixed by #625
Assignees
Labels
bug This Issue describes a unwanted behavior next release This issue will be solve/implemented in the next release

Comments

@khase
Copy link
Collaborator

khase commented Sep 20, 2017

 User
    GET /api/users
      βœ“ should return all users
      βœ“ should fail with wrong authorization
    GET /api/users/roles
      βœ“ should fail with wrong authorization
      βœ“ should return an array with the defined roles
    PUT /api/users
(node:7360) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Can't set headers after they are sent.
(node:7360) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
      βœ“ should fail with bad request (admin privileges)
      βœ“ should fail with bad request (email)
      βœ“ should fail with wrong authorization (role edit)
      βœ“ should fail with wrong authorization (uid)
      βœ“ should update user data
@khase khase added the bug This Issue describes a unwanted behavior label Sep 20, 2017
@grosspersky
Copy link
Collaborator

Comes from this function:

  @Get('/')
  @Authorized(['teacher', 'admin'])
  getUsers(@CurrentUser() currentUser?: IUser) {
    return User.find({})
      .then((users) => {
        return users.map((user) => this.cleanUserObject(null, user, currentUser));
      });
  }

@felixbrucker
Copy link
Collaborator

felixbrucker commented Nov 30, 2017

@grosspersky this is not correct

It occurs because of these two functions: https://github.com/h-da/geli/blob/develop/api/src/controllers/UserController.ts#L40-L54

This happens because the route /users/roles also matches /users/:id

as a result both functions are called and the second one fails to set the headers because the response got already sent by the other function

@aeimer aeimer changed the title Unhandeled Promise Rejection in User tests. BUG: Unhandeled Promise Rejection in User tests. Jan 31, 2018
@aeimer aeimer changed the title BUG: Unhandeled Promise Rejection in User tests. πŸ› BUG: Unhandeled Promise Rejection in User tests. Jan 31, 2018
@PatrickSkowronek PatrickSkowronek added the next release This issue will be solve/implemented in the next release label Apr 9, 2018
@a-siewe a-siewe self-assigned this Apr 12, 2018
a-siewe added a commit that referenced this issue Apr 14, 2018
- return status code 404 if user not found
- use regex on id parameter to avoid /users/roles matching /users/:id

close #204
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This Issue describes a unwanted behavior next release This issue will be solve/implemented in the next release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants