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

BaseService: Query params #1589

Merged
merged 10 commits into from
Jun 16, 2018
Merged

BaseService: Query params #1589

merged 10 commits into from
Jun 16, 2018

Conversation

paulmelnikow
Copy link
Member

@paulmelnikow paulmelnikow commented Mar 20, 2018

This is a fairly straightforward improvement to BaseService which provides support for query parameters, in parity with the functionality in old-style services

This functionality is necessary to port many of the existing services, and arose while I was working on this WIP branch: master...paulmelnikow:rewrite-npm-typedefs

@paulmelnikow paulmelnikow added the core Server, BaseService, GitHub auth, Shared helpers label Mar 20, 2018
@shields-ci
Copy link

shields-ci commented Mar 20, 2018

Messages
📖

✨ Thanks for your contribution to Shields, @paulmelnikow!

Generated by 🚫 dangerJS

# Conflicts:
#	services/base.js
@chris48s
Copy link
Member

@platan do you mind taking the review of this one?

# Conflicts:
#	services/base.spec.js
@paulmelnikow
Copy link
Member Author

It would be really great if our bus factor on this BaseService code were greater than 1. It's so essential to how Shields works! If the code is hard to understand, it's important we make it clearer… and all the more reason to address those issues before the problem becomes even harder to tackle.

@platan Can I implore your review? 👐

@paulmelnikow paulmelnikow changed the title BaseService: Handle query params BaseService: Query params Apr 2, 2018
# Conflicts:
#	services/base.js
#	services/base.spec.js
@platan
Copy link
Member

platan commented Apr 2, 2018

@paulmelnikow I'm starting to read it ...

Copy link
Member

@platan platan left a comment

Choose a reason for hiding this comment

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

Changes in production code are simple and are OK. But changes in test code were difficult to understand for me. DummyService does nothing specific and you have to memorize it internals before analyzing test code. I've left some suggestions, they could improve understanding of the code.

@@ -38,6 +38,9 @@ module.exports = class BaseService {
* - capture: Array of names for the capture groups in the regular
* expression. The handler will be passed an object containing
* the matches.
* - queryParams: Array of names for query parameters which will the service
Copy link
Member

Choose a reason for hiding this comment

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

A few lines above there is Returns an object with two fields:. Now we have 3 fields.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, looks like this was addressed in #1582.

}

static get category() { return 'cat'; }
static get url() {
return {
base: 'foo',
format: '([^/]+)',
capture: ['someArg']
capture: ['someArg'],
Copy link
Member

Choose a reason for hiding this comment

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

Can we rename someArg to namedArgA (or namedArg1).

}

static get category() { return 'cat'; }
static get url() {
return {
base: 'foo',
format: '([^/]+)',
capture: ['someArg']
capture: ['someArg'],
queryParams: ['suffix'],
Copy link
Member

Choose a reason for hiding this comment

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

Can we rename suffix to queryParamA?

message: 'Hello ' + someArg,
};
async handle({ someArg }, { suffix }) {
return { message: `Hello ${someArg}${suffix}` };
Copy link
Member

Choose a reason for hiding this comment

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

How about this?

return { message: `Hello namedParamA${namedParamA} with queryParamA${quaryParamA}` };

Copy link
Member Author

Choose a reason for hiding this comment

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

Works for me!


const mockSendBadge = sinon.spy();
const mockRequest = {
asPromise: sinon.spy(),
};
await requestHandler(
/*data*/ {},
/*queryParams*/ { suffix: '?' },
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about extracting the first and the second arguments to variables?

      const queryParams = { suffix: '?' };
      const match = '/foo/bar.svg'.match(expectedRouteRegex);
      await requestHandler(
        queryParams,
        match,
        mockSendBadge,
        mockRequest
      );

@@ -162,7 +163,7 @@ describe('BaseService', () => {
expect(mockSendBadge).to.have.been.calledWith(
/*format*/ 'svg',
Copy link
Member

Choose a reason for hiding this comment

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

How about extracting svg to a variable?

@paulmelnikow
Copy link
Member Author

Thank you so much for the review!

But changes in test code were difficult to understand for me. DummyService does nothing specific and you have to memorize it internals before analyzing test code. I've left some suggestions, they could improve understanding of the code.

I'm totally open to improving this. Maybe we could think about creating a dummy service which has clearer semantics.

@paulmelnikow paulmelnikow merged commit 20b8d0c into badges:master Jun 16, 2018
@shields-deployment
Copy link

shields-deployment bot commented Jun 16, 2018

This pull request was merged to master branch. Now this change is waiting for deployment.
Deploys usually happen every few weeks. After deployment changes are copied to gh-pages branch.

This badge displays deployment status:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Server, BaseService, GitHub auth, Shared helpers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants