Skip to content

Hotfix/user level reports #530

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

Merged
merged 8 commits into from
Apr 9, 2020
Merged

Hotfix/user level reports #530

merged 8 commits into from
Apr 9, 2020

Conversation

vikasrohit
Copy link

No description provided.

@vikasrohit vikasrohit requested a review from maxceem April 8, 2020 08:29
const resJson = res.body;
should.exist(resJson);
resJson.should.equal('generatedUrl');
const [user, project, member, embedUrl] = gem.lastCall.args;
Copy link
Contributor

Choose a reason for hiding this comment

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

@vikasrohit I'm not sure how does it work. Here gem.lastCall.args is used but a few lines above on line 250 it's restored by gem.restore().

Copy link
Author

Choose a reason for hiding this comment

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

Yes, that is valid argument. However, I just copied the unit tests we already have for project reports route and updated them to meet my requirements. :)

Copy link
Author

Choose a reason for hiding this comment

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

And strange thing is that, it is working fine. However, I did find one minor issue with unit tests of project reports route, they are still using magic numbers i.e. user ids are used as numbers instead of using them from the variables/constants and I fixed that in my unit tests.

Copy link
Contributor

@maxceem maxceem Apr 9, 2020

Choose a reason for hiding this comment

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

Hey, @xxcxy could you please help us to clarify this moment how does it work?

first it restores the stub:

gem.restore();

and after it uses it for testing:

const [user, project, member, embedUrl] = gem.lastCall.args;

See initial code d08f9f3#diff-fa4fefc23d4de0d05b580cf93c44207bR206

@maxceem
Copy link
Contributor

maxceem commented Apr 9, 2020

I guess it's not critical, but we usually return responses in JSON, including situations when some error happens. In the report endpoints in case of errors responses are returned as plain text. Here are some examples and how they could be rewritten to return JSON.

return res.status(500).send(err.toString());

can be replaced by:

next(err);  // this would set HTTP status of error to `500` by default and format error JSON response properly

When some custom error code should be returned like for this case:

return res.status(403).send('User is not allowed to access the report');

it can be replaced by:

const err = new Error('User is not allowed to access the report');
err.status = 403;
return next(err);

Copy link
Contributor

@maxceem maxceem left a comment

Choose a reason for hiding this comment

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

Other than returning strings instead of JSON in case of errors everything else looks good to me.

@vikasrohit
Copy link
Author

vikasrohit commented Apr 9, 2020

Other than returning strings instead of JSON in case of errors everything else looks good to me.

I thought of it but my thought process was because we return resources in response and for this endpoint the resource is actually the URL which is primitive data type instead of object. Still, we can think on it later and can fix it in a combined efforts.

We can fix the error response similarly later. Just curious, are we using that way of sending error responses in all other routes?

@maxceem
Copy link
Contributor

maxceem commented Apr 9, 2020

I thought of it but my thought process was because we return resources in response and for this endpoint the resource is actually the URL which is primitive data type instead of object. Still, we can think on it later and can fix it in a combined efforts.

Sure, it's not critical. Just for consistency, it's nice to know that we always get JSON in response, also to comply with Topcoder API V5 standard:

image

We can fix the error response similarly later. Just curious, are we using that way of sending error responses in all other routes?

Yes, all other routes return JSON in case of errors (at least I don't any which don't).

@vikasrohit vikasrohit merged commit 7e3be06 into master Apr 9, 2020
@vikasrohit vikasrohit deleted the hotfix/user_level_reports branch November 16, 2020 08:08
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.

2 participants