Implement getEndpoints - #305
Conversation
|
I am proposing to preserve backwards compatibility of this API to make migration easier, and provide new methods for the functionality we need. We can mark the old methods as deprecated, it will make it easier to find all places calling them. RestMethod.prototype.getHttpMethod = function() {
deprecated('getHttpMethod() is deprecated, use getFirstHttpMethod() instead.');
return this.getFirstHttpMethod();
};
RestMethod.prototype.getFirstHttpMethod = function() {
return this.getAllHttpMethods()[0];
};
RestMethod.prototype.getAllHttpMethods = function() {
// the real works is done here
}; |
| it('returns POST for `all`', function() { | ||
| var method = givenRestStaticMethod({ http: { verb: 'all' }}); | ||
| expect(method.getHttpMethod()).to.equal('POST'); | ||
| expect(method.getHttpMethod()[0]).to.equal('POST'); |
There was a problem hiding this comment.
With the ability to get all methods in place, we should test all members of the array returned.
expect(method.getAllHttpMethods()).to.eql(['POST']);7195b5c to
c0c22ea
Compare
|
Hey @rmg I see lots of failures for dependencies like the following. Any thought about this? Thanks! and |
|
When that temporary registry is killed, anything trying to install from it will fail. This can happen if one of the dependents fails and triggers a registry shutdown. |
|
@bajtos PTAL :-) This PR needs to be landed to unblock me from working on: strongloop/loopback#2316 |
| return this.getFirstHttpMethod(); | ||
| }; | ||
|
|
||
| RestMethod.prototype.getFirstHttpMethod = function() { |
There was a problem hiding this comment.
On the second thought, I think getFirstHttpMethod may be not worth the API pollution. Users can always call this.getEndpoints()[0].verb themselves. What do you think?
|
@Amir-61 please add a test to verify that Also what happens when you run the test suite, does it trigger deprecation warnings because we still call |
|
@bajtos Please review another round :-)
If you mean Also, this generateRestMethodWithMultiplePaths may be messy. would you do it in the same way? How would you do that?
|
It's good to show deprecation messages for strong-remoting users, but it's not great to see them when running a test suite. I am proposing the following:
I would simply call the existing helper givenRestStaticMethod({ http: [
{ verb: 'DEL', path: '/testMethod1' },
{ verb: 'PUT', path: '/testMethod2' }
]});Unless I am missing a reason why this would not work? BTW I think we should backport this patch to 2.x too. |
| before(function() { | ||
| process.env.NO_DEPRECATION = 'strong-remoting'; | ||
| }); | ||
|
|
There was a problem hiding this comment.
I am proposing the following:
- Rework all tests using deprecated methods to use the new official methods
- In unit-tests that are testing specifically these deprecated methods, temporarily disable deprecation messages via https://github.com/dougwilson/nodejs-depd#processenvno_deprecation
I reworked on where we were using deprecated getHttpMethod and getPath to use our new official methods, but here that we we are explicitly testing these deprecated methods, I should just have them untouched, and need to disable deprecation messages temporarily. I tried process.env.NO_DEPRECATION = 'strong-remoting'; but still it shows the deprecation messages...
Also it is worth mentioning that there are many other deprecated messages for other methods (not getHttpMethod or getPath)which are shown when you run tests for strong-remoting, I did not touch them because I thought it is out of scope of this PR.
There was a problem hiding this comment.
Oh, I think I know what's the problem: depd initializes when the file is require-d, thus changing env.NO_DEPRECATION at runtime has no effect. Can you try to use process.on('deprecation') instead? See docs.
There was a problem hiding this comment.
You also need an after handler to reset the environment (remove the listener), so that deprecations are printed again.
ca7b00f to
b8acb0f
Compare
| HttpInvocation.prototype.createRequest = function() { | ||
| var method = this.method; | ||
| var verb = method.getHttpMethod(); | ||
| var verb = method.getEndpoints()[0].verb; |
There was a problem hiding this comment.
perhaps store the endpoint, so that we don't have to repeat method.getEndpoints[0]?
var endpoint = method.getEndpoints()[0]);
var verb = endpoints.verb;
//...
req.url = this.base + endpoint.fullPath;Thoughts?
|
@Amir-61 LGTM. The current version disables deprecation warnings printed from all tests in Also I think the new API should be back-ported to 2.x too, possibly without deprecation warnings. Thoughts? |
98dbeba to
18116de
Compare
|
@bajtos I did not want to leave you unhappy so I did not land the PR to make sure you are happy with it :-) I fixed it now. please take a look again. Also there are other deprecated methods (like sharedClass.find(), sharedClass.disableMethod(methodName, isStatic)) that we were testing specifically in |
|
|
||
| after(function() { | ||
| process.removeListener('deprecation', NOOP); | ||
| }); |
There was a problem hiding this comment.
Nitpick: add an empty line to visually delimit after/it blocks.
Idea to consider: extract these two before/after blocks into a shared helper method.
describe('getFullPath', function() {
ignoreDeprecationsInThisBlock();
it('returns class path + method path', /*...*/);
});Thoughts?
There was a problem hiding this comment.
I addressed this and pushed the change. Thanks!
fed11a2 to
edd0595
Compare
|
Lovely 👏 Could you please fix commit message summary to use Last but not least, please check why some of the dependants are failing, to make sure the failures are not related. No further review is necessary. |
* Implement getEndpoints * Deprecate getHttpMethod * Deprecate getFullPath
edd0595 to
d44af88
Compare
Unfortunately, failures are so random and they are not code relevant either. They all fail with this error: If I run many times by chance one of them may pass. I add the ci failures in our Considering the fact that failures are not code relevant, may I merge the code? CC: @rmg ADDED:Oh nvm; after running tests a couple of more times. It eventually passed tests and now merging the code. |
|
@slnode test please |
This patch includes:
getEndpointswhich returns an array of objects, showing verbs and pathsgetHttpMethodgetFullPath/to: @bajtos