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

feat: Impossible to use UUID as param for object construction #706 #708

Closed

Conversation

ivanproskuryakov
Copy link
Contributor

Description

The usage of UUID instead of id in routes like http://0.0.0.0:3000/api/products/04879b32-c329-48d7-a652-818794b684f1
Is trying to build JSON object while returning a raw parameter(UUID) provided.

Ref: #703

Checklist

  • the pull request title describes what this PR does (not a vague title like Update index.md)
  • the pull request targets the default branch of the repository (develop)
  • the code follows the established code style of the repository
    • npm run prettier:check passes
    • npm run lint:check passes
  • [s] tests are added for the changes I made (if any source code was modified)
  • documentation added or updated
  • I have run the project locally and verified that there are no errors

Fixes

The conditions the inside normalizeParamValue now excluding "param" type, keeping UUID strings untouched

typeof value === 'object' &&
['queries', 'headers', 'params', 'cookies'].some(paramType => paramType === param.type)
) {
['queries', 'headers', 'params', 'cookies'].some(paramType => paramType === param.type);
Copy link

Choose a reason for hiding this comment

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

includes() would be better in this case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

['queries', 'headers', 'params', 'cookies'].some(paramType => paramType === param.type)
) {
['queries', 'headers', 'params', 'cookies'].some(paramType => paramType === param.type);
const isTargetPrimitive = ['number', 'string', 'boolean'].indexOf(param.targetName) > -1;
Copy link

Choose a reason for hiding this comment

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

Also use includes() here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

const expect = require('chakram').expect;

describe('ActionParameterHandler', () => {
it('handle', async () => {
Copy link

Choose a reason for hiding this comment

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

You should add negative and positive cases

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Broader test coverage was added including two negative tests:


PASS test/ActionParameterHandler.spec.ts
ActionParameterHandler
✓ handle - should process string parameters (154 ms)
✓ handle - should process string parameters, returns empty if a given string is empty
✓ handle - should process number parameters (1 ms)
✓ handle - undefined on empty object provided
✓ handle - throws error if the parameter is required
✓ handle - throws error if the parameter is required, type file provided (10 ms)

});

it('handle - throws error if the parameter is required', async () => {
const driver = new ExpressDriver();
Copy link

Choose a reason for hiding this comment

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

You should wrap these negative cases with describe('negative', () => {}) and add beforeEach with

const driver = new ExpressDriver();
    const actionParameterHandler = new ActionParameterHandler(driver);
    const param = buildParamMetadata('uuid', 'file', true);

});

it('handle - should process string parameters, returns empty if a given string is empty', async () => {
const driver = new ExpressDriver();
Copy link

@qdanik qdanik Apr 18, 2021

Choose a reason for hiding this comment

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

Look at my comment above and do the same with describe('positive', () => {})

Copy link

Choose a reason for hiding this comment

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

But, these 3 positive cases have only two common variables:

const driver = new ExpressDriver();
const actionParameterHandler = new ActionParameterHandler(driver);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@qdanik thanks for the review and valuable feedback!
Could you take a look once again, please?

Copy link

Choose a reason for hiding this comment

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

@ivanproskuryakov Looks good for me. Please add @NoNameProvided into Reviewers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@qdanik can't do so myself, this functionality is not available to me.

qdanik
qdanik previously approved these changes Apr 20, 2021
Copy link

@qdanik qdanik 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 for me

@ivanproskuryakov
Copy link
Contributor Author

@qdanik @nolazybits @fabiob could the PR be merged, please?

fabiob
fabiob previously approved these changes May 31, 2021
@ivanproskuryakov
Copy link
Contributor Author

@nolazybits @jvelo @fabiob ping 📦

@fabiob
Copy link
Contributor

fabiob commented Jun 11, 2021

LGTM, but I don't have write access.

noeoliveira
noeoliveira previously approved these changes Jun 21, 2021
@ivanproskuryakov
Copy link
Contributor Author

@MichalLytek @jotamorais @NoNameProvided @rustamwin hi, can we merge this PR?

rustamwin
rustamwin previously approved these changes Jul 7, 2021
src/ActionParameterHandler.ts Outdated Show resolved Hide resolved
Co-authored-by: Rustam Mamadaminov <rmamdaminov@gmail.com>
typeof value === 'object' &&
['queries', 'headers', 'params', 'cookies'].some(paramType => paramType === param.type)
) {
if (isNormalisationNeeded) {

Choose a reason for hiding this comment

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

Suggested change
if (isNormalisationNeeded) {
if (isNormalizationNeeded) {

@ivanproskuryakov ivanproskuryakov force-pushed the uuid-parameters-703 branch 2 times, most recently from 33a38c5 to 2a3fa2b Compare July 20, 2021 12:08
@ivanproskuryakov
Copy link
Contributor Author

@rustamwin closed because to merging conflicts, the new PR - #753

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants