Skip to content

Commit

Permalink
Test coverage for the deployment adapter action
Browse files Browse the repository at this point in the history
  • Loading branch information
DingoEatingFuzz committed Jul 21, 2020
1 parent eb3ea89 commit 01c5c4e
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions ui/tests/unit/adapters/deployment-test.js
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,
});
});
});
});

0 comments on commit 01c5c4e

Please sign in to comment.