Skip to content

Conversation

@ManethKulatunge
Copy link
Contributor

@ManethKulatunge ManethKulatunge commented Dec 8, 2019

Tickets:

List of changes:

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

  • Added a /accept/:id route that can accept a hacker by ID

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How has this been tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Failure on someone who is not authenticated
    Failure on someone who is not authorized
    Failure on invalid input
    Success for accepting a hacker.
    On hacker.test.js

  • POSTMAN Patch request to hacker/accept/:id

Test Configuration:

Firmware version:
Hardware:
Toolchain:
SDK:

Questions for code reviewers?

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have made corresponding changes to the documentation
  • Any dependent changes have been merged and published in downstream modules

@ManethKulatunge ManethKulatunge force-pushed the feature/152-accept-hacker-route branch 2 times, most recently from 67ef3bf to e863783 Compare December 8, 2019 16:12
*/
async function acceptHacker(req, res, next) {
req.body.status = Constants.General.HACKER_STATUS_ACCEPTED;
updateHacker(req, res, next);
Copy link

@printharsh printharsh Dec 8, 2019

Choose a reason for hiding this comment

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

Since this is a middleware, just put it under the route, remove this line and call next()

Copy link
Member

Choose a reason for hiding this comment

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

To add onto Harsh's comment:

function parseAccept(req, res, next) {
    req.body.status = Constants.General.HACKER_STATUS_ACCEPTED;
    next();
}

and then in routes/hacker.js:

...
Middleware.Hacker.parseAccept,
Middleware.Hacker.updateHacker,
...

}

/**
* Sets Hacker Status to Accepted and runs it through updateHacker's functionality.

Choose a reason for hiding this comment

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

Nit: Rename function to parseAccept, similar to parseConfirmation and make comment just say it sets the req.body.status to accepted

Copy link

@printharsh printharsh left a comment

Choose a reason for hiding this comment

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

Looks good! Just very minor nits, could you also add some tests (under hacker.test.js PATCH update one hacker tests should be very similar to the ones you'd write).

Copy link
Member

@pierreTklein pierreTklein left a comment

Choose a reason for hiding this comment

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

LGTM, added to Harsh's comment.

*/
async function acceptHacker(req, res, next) {
req.body.status = Constants.General.HACKER_STATUS_ACCEPTED;
updateHacker(req, res, next);
Copy link
Member

Choose a reason for hiding this comment

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

To add onto Harsh's comment:

function parseAccept(req, res, next) {
    req.body.status = Constants.General.HACKER_STATUS_ACCEPTED;
    next();
}

and then in routes/hacker.js:

...
Middleware.Hacker.parseAccept,
Middleware.Hacker.updateHacker,
...

* @param {*} res
* @param {*} next
*/
async function acceptHacker(req, res, next) {
Copy link
Member

Choose a reason for hiding this comment

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

This function should not be async.

Copy link
Member

@pierreTklein pierreTklein left a comment

Choose a reason for hiding this comment

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

Please include some additional tests for this route:

  • Failure on someone who is not authenticated
  • Failure on someone who is not authorized
  • Failure on invalid input
  • Success for accepting a hacker.

@ManethKulatunge ManethKulatunge force-pushed the feature/152-accept-hacker-route branch from 421c6d3 to 21b999a Compare December 8, 2019 21:36
Copy link
Member

@loreina loreina left a comment

Choose a reason for hiding this comment

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

can we revert changes that happened in docs folder aside from your changes

@ManethKulatunge ManethKulatunge force-pushed the feature/152-accept-hacker-route branch from 788c7b7 to e36f3a9 Compare December 9, 2019 04:09
@ManethKulatunge ManethKulatunge force-pushed the feature/152-accept-hacker-route branch from e36f3a9 to d4264c5 Compare December 9, 2019 04:24
Copy link
Member

@loreina loreina left a comment

Choose a reason for hiding this comment

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

one versioning change, everything else looks great !!!

Co-Authored-By: Loreina Chew <loreina.chew@gmail.com>
@ManethKulatunge ManethKulatunge merged commit 54b385c into develop Dec 9, 2019
@ManethKulatunge ManethKulatunge deleted the feature/152-accept-hacker-route branch December 9, 2019 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants