2020-07-21 06:18:15 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupTest } from 'ember-qunit';
|
|
|
|
import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
module('Unit | Adapter | Deployment', function (hooks) {
|
2020-07-21 06:18:15 +00:00
|
|
|
setupTest(hooks);
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
hooks.beforeEach(async function () {
|
2020-07-21 06:18:15 +00:00
|
|
|
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 });
|
2021-12-28 16:08:12 +00:00
|
|
|
const deploymentRecord = server.schema.deployments.where({
|
|
|
|
jobId: job.id,
|
|
|
|
}).models[0];
|
2020-07-21 06:18:15 +00:00
|
|
|
|
|
|
|
this.system.get('shouldIncludeRegion');
|
|
|
|
await this.system.get('defaultRegion');
|
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
const deployment = await this.store.findRecord(
|
|
|
|
'deployment',
|
|
|
|
deploymentRecord.id
|
|
|
|
);
|
2020-07-21 06:18:15 +00:00
|
|
|
this.server.pretender.handledRequests.length = 0;
|
|
|
|
|
|
|
|
return deployment;
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
hooks.afterEach(function () {
|
2020-07-21 06:18:15 +00:00
|
|
|
this.server.shutdown();
|
|
|
|
});
|
|
|
|
|
|
|
|
const testCases = [
|
|
|
|
{
|
|
|
|
variation: '',
|
|
|
|
region: null,
|
2021-12-28 14:45:20 +00:00
|
|
|
fail: (id) => `POST /v1/deployment/fail/${id}`,
|
|
|
|
promote: (id) => `POST /v1/deployment/promote/${id}`,
|
2020-07-21 06:18:15 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
variation: 'with non-default region',
|
|
|
|
region: 'region-2',
|
2021-12-28 14:45:20 +00:00
|
|
|
fail: (id) => `POST /v1/deployment/fail/${id}?region=region-2`,
|
|
|
|
promote: (id) => `POST /v1/deployment/promote/${id}?region=region-2`,
|
2020-07-21 06:18:15 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
testCases.forEach((testCase) => {
|
|
|
|
test(`promote makes the correct API call ${testCase.variation}`, async function (assert) {
|
2020-07-21 06:18:15 +00:00
|
|
|
const deployment = await this.initialize({ region: testCase.region });
|
|
|
|
await this.subject().promote(deployment);
|
|
|
|
|
|
|
|
const request = this.server.pretender.handledRequests[0];
|
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
`${request.method} ${request.url}`,
|
|
|
|
testCase.promote(deployment.id)
|
|
|
|
);
|
2020-07-21 06:18:15 +00:00
|
|
|
assert.deepEqual(JSON.parse(request.requestBody), {
|
|
|
|
DeploymentId: deployment.id,
|
|
|
|
All: true,
|
|
|
|
});
|
|
|
|
});
|
2021-02-10 14:38:37 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test(`fail makes the correct API call ${testCase.variation}`, async function (assert) {
|
2021-02-10 14:38:37 +00:00
|
|
|
const deployment = await this.initialize({ region: testCase.region });
|
|
|
|
await this.subject().fail(deployment);
|
|
|
|
|
|
|
|
const request = this.server.pretender.handledRequests[0];
|
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
`${request.method} ${request.url}`,
|
|
|
|
testCase.fail(deployment.id)
|
|
|
|
);
|
2021-02-10 14:38:37 +00:00
|
|
|
assert.deepEqual(JSON.parse(request.requestBody), {
|
|
|
|
DeploymentId: deployment.id,
|
|
|
|
});
|
|
|
|
});
|
2020-07-21 06:18:15 +00:00
|
|
|
});
|
|
|
|
});
|