-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8477 from hashicorp/b-ui/cross-region-alloc-lifec…
…ycle-buttons UI: Always add the active region as a query param to API requests
- Loading branch information
Showing
6 changed files
with
385 additions
and
172 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupTest } from 'ember-qunit'; | ||
import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage'; | ||
|
||
module('Unit | Adapter | Deployment', function(hooks) { | ||
setupTest(hooks); | ||
|
||
hooks.beforeEach(async function() { | ||
this.store = this.owner.lookup('service:store'); | ||
this.system = this.owner.lookup('service:system'); | ||
this.subject = () => this.store.adapterFor('deployment'); | ||
|
||
window.localStorage.clear(); | ||
|
||
this.server = startMirage(); | ||
|
||
this.initialize = async ({ region } = {}) => { | ||
if (region) window.localStorage.nomadActiveRegion = region; | ||
|
||
this.server.create('region', { id: 'region-1' }); | ||
this.server.create('region', { id: 'region-2' }); | ||
|
||
this.server.create('node'); | ||
const job = this.server.create('job', { createAllocations: false }); | ||
const deploymentRecord = server.schema.deployments.where({ jobId: job.id }).models[0]; | ||
|
||
this.system.get('shouldIncludeRegion'); | ||
await this.system.get('defaultRegion'); | ||
|
||
const deployment = await this.store.findRecord('deployment', deploymentRecord.id); | ||
this.server.pretender.handledRequests.length = 0; | ||
|
||
return deployment; | ||
}; | ||
}); | ||
|
||
hooks.afterEach(function() { | ||
this.server.shutdown(); | ||
}); | ||
|
||
const testCases = [ | ||
{ | ||
variation: '', | ||
region: null, | ||
promote: id => `POST /v1/deployment/promote/${id}`, | ||
}, | ||
{ | ||
variation: 'with non-default region', | ||
region: 'region-2', | ||
promote: id => `POST /v1/deployment/promote/${id}?region=region-2`, | ||
}, | ||
]; | ||
|
||
testCases.forEach(testCase => { | ||
test(`promote makes the correct API call ${testCase.variation}`, async function(assert) { | ||
const deployment = await this.initialize({ region: testCase.region }); | ||
await this.subject().promote(deployment); | ||
|
||
const request = this.server.pretender.handledRequests[0]; | ||
|
||
assert.equal(`${request.method} ${request.url}`, testCase.promote(deployment.id)); | ||
assert.deepEqual(JSON.parse(request.requestBody), { | ||
DeploymentId: deployment.id, | ||
All: true, | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.