Conversation
davobutt
suggested changes
Sep 5, 2017
| // We already have these resources | ||
| return | ||
| } | ||
| if (resource.links && resource.links[include]) { |
Contributor
There was a problem hiding this comment.
Not really in your change, but don't think you can get here and resource.links not be truthy.
Given that you could I suppose go with
if (resource.links[include] && !(stateObject.linked && stateObject.linked[include])) {
utilities._addSubResourceRequest(stateObject.subResourceRequests, resource.links[include])
}
But not sure that adds much to readability.
| return expect(utilities.getSubResources(stateObject)).to.eventually.deep.equal(expected) | ||
| }) | ||
| }) | ||
|
|
Contributor
There was a problem hiding this comment.
Free Gift ;-)
I wrote this test to satisfy myself...
it('should not attach any already linked sub resources, but still add unlinked ones', function () {
var stateObject = {
resources: [
{
id: 'ID',
links: {
LINK1: {
ids: ['LINK_ID1'],
type: 'LINK1'
},
LINK2: {
ids: ['LINK_ID2'],
type: 'LINK2'
}
}
}
],
includes: ['LINK1', 'LINK2'],
linked: {
LINK1: []
}
}
var expected = _.cloneDeep(stateObject)
expected.subResourceRequests = {
LINK2: {
ids: ['LINK_ID2']
}
}
return expect(utilities.getSubResources(stateObject)).to.eventually.deep.equal(expected)
})
davobutt
approved these changes
Sep 7, 2017
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do? (please provide any background)
https://hxshortbreaks.atlassian.net/browse/FP-1042
Some The Works endpoints now create their own
linkedresources (see https://github.com/holidayextras/the-works/pull/590 which will consume this work once merged) removing the need for plugin-jsonapi to request them. Plugin-jsonapi now handles this by checking for the presence of linked includes before adding them onto the request array.This is a performance/optimisation piece.
What tests does this PR have?
One additional test to cover the additional usecase of the
getSubResourcesfunctionHow can this be tested?
On it's own, not so much. Pull down https://github.com/holidayextras/the-works/pull/590 and run a GET /packageRates request with an
includeofticketRates,roomRates,hotelProducts. You will then see plugin-jsonapi only request thehotelProductsas the packageRates endpoint will return the ticketRates and roomRates resources itself.Any tech debt?
None
Screenshots / Screencast
What gif best describes how you feel about this work?
By approving a review you are confirming you have...