open-nomad/ui/tests/unit/adapters/deployment-test.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

94 lines
2.8 KiB
JavaScript
Raw Normal View History

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) {
setupTest(hooks);
2021-12-28 14:45:20 +00:00
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 });
2021-12-28 16:08:12 +00:00
const deploymentRecord = server.schema.deployments.where({
jobId: job.id,
}).models[0];
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
);
this.server.pretender.handledRequests.length = 0;
return deployment;
};
});
2021-12-28 14:45:20 +00:00
hooks.afterEach(function () {
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}`,
},
{
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`,
},
];
2021-12-28 14:45:20 +00:00
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];
2021-12-28 16:08:12 +00:00
assert.equal(
`${request.method} ${request.url}`,
testCase.promote(deployment.id)
);
assert.deepEqual(JSON.parse(request.requestBody), {
DeploymentId: deployment.id,
All: true,
});
});
2021-12-28 14:45:20 +00:00
test(`fail makes the correct API call ${testCase.variation}`, async function (assert) {
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)
);
assert.deepEqual(JSON.parse(request.requestBody), {
DeploymentId: deployment.id,
});
});
});
});