-
Notifications
You must be signed in to change notification settings - Fork 2k
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
UI: Always add the active region as a query param to API requests #8477
UI: Always add the active region as a query param to API requests #8477
Conversation
Ember Asset Size actionAs of 544d941 Files that got Bigger 🚨:
Files that stayed the same size 🤷:
|
Ember Test Audit comparison
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a couple of minor comments but nothing blocking. I didn’t run this locally but I did check it out on Netlify with mirage-logging=true
and all looks well 😀
const region = this.get('system.activeRegion'); | ||
if (region) { | ||
options.data.region = region; | ||
url = associateRegion(url, region); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A nice clean intervention! 😍
ui/tests/unit/adapters/node-test.js
Outdated
@@ -9,9 +9,16 @@ module('Unit | Adapter | Node', function(hooks) { | |||
|
|||
hooks.beforeEach(function() { | |||
this.store = this.owner.lookup('service:store'); | |||
this.system = this.owner.lookup('service:system'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quite minor but it looks like this isn’t accessed anywhere in this test 🤓
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
testCases.forEach(testCase => { | ||
test(`setEligible makes the correct POST request to /:node_id/eligibility ${testCase.variation}`, async function(assert) { | ||
const { pretender } = this.server; | ||
if (testCase.region) window.localStorage.nomadActiveRegion = testCase.region; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not sure this would work but I wonder if this repeated setup step could be extracted with something like this inside testCases.forEach
:
if (testCase.region) {
hooks.beforeEach(function() {
window.localStorage.nomadActiveRegion = testCase.region;
});
}
Maybe it’s not worth it though, since there would still be other boilerplate-ish things shared between tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this and it did not work. I think since tests can run in any order, the only way to make this work is to give each test case its own module...but I'm gonna avoid the nerd snipe 😅
This involves a refactor to prevent immense verbosity.
01c5c4e
to
544d941
Compare
I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions. |
Fixes #7309 #8195
This was a straightforward fix but it shone a light on a pretty big test coverage gap. As a consequence, most of this diff is new tests and test refactoring.
Root issue
The root issue is a sorta clumsy intersection of a few truths and a lack of testing on our part.
region
query parameter.PUT
,POST
, andDELETE
requests is unorthodox. Typically if a request has a request body, it doesn't also have query params.data
will be encoded as query params forGET
requests and asrequestBody
properties for all other requests.Resolution
All API requests going through Ember Data eventually hit the
ajaxOptions
method of the application adapter. This is already where theregion
param handling was happening. Now instead of stuffing the property in thedata
hash, it is manually appended to the URL as a query param.All API requests going through the token service were unaffected since the region was already manually being added as a query param.
To ensure this is true everywhere and to set a precedent going forward, unit tests for all adapter actions now include variations for use with a non-default region. This includes
fetchRawDefinition
forcePeriodic
stop
parse
plan
run
update
scale
stop
restart
stat
promote
setEligible
setIneligible
drain
forceDrain
cancelDrain