Skip to content

Commit

Permalink
Test coverage for the promote canary feature
Browse files Browse the repository at this point in the history
  • Loading branch information
DingoEatingFuzz committed Aug 24, 2018
1 parent 49e54a3 commit 1f5e3a8
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</span>
{{#if job.latestDeployment.requiresPromotion}}
<button
data-test-promote-canary
type="button"
class="button is-warning is-small pull-right {{if promote.isRunning "is-loading"}}"
disabled={{promote.isRunning}}
Expand Down
3 changes: 3 additions & 0 deletions ui/mirage/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ export default function() {
});

this.get('/deployment/:id');
this.post('/deployment/promote/:id', function() {
return new Response(204, {}, '');
});

this.get('/job/:id/evaluations', function({ evaluations }, { params }) {
return this.serialize(evaluations.where({ jobId: params.id }));
Expand Down
2 changes: 2 additions & 0 deletions ui/mirage/factories/deployment-task-group-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export default Factory.extend({
autoRevert: () => Math.random() > 0.5,
promoted: () => Math.random() > 0.5,

requiresPromotion: false,

requireProgressBy: () => faker.date.past(0.5 / 365, REF_TIME),

desiredTotal: faker.random.number({ min: 1, max: 10 }),
Expand Down
2 changes: 2 additions & 0 deletions ui/mirage/factories/deployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export default Factory.extend({
server.create('deployment-task-group-summary', {
deployment,
name: server.db.taskGroups.find(id).name,
desiredCanaries: 1,
promoted: false,
})
);

Expand Down
78 changes: 78 additions & 0 deletions ui/tests/integration/job-page/service-test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { getOwner } from '@ember/application';
import { assign } from '@ember/polyfills';
import { test, moduleForComponent } from 'ember-qunit';
import { click, find } from 'ember-native-dom-helpers';
import wait from 'ember-test-helpers/wait';
import hbs from 'htmlbars-inline-precompile';
import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
import { stopJob, expectStopError, expectDeleteRequest } from './helpers';
import Job from 'nomad-ui/tests/pages/jobs/detail';
import { initialize as fragmentSerializerInitializer } from 'nomad-ui/initializers/fragment-serializer';
import { later } from '@ember/runloop';

moduleForComponent('job-page/service', 'Integration | Component | job-page/service', {
integration: true,
beforeEach() {
Job.setContext(this);
fragmentSerializerInitializer(getOwner(this));
window.localStorage.clear();
this.store = getOwner(this).lookup('service:store');
this.server = startMirage();
Expand Down Expand Up @@ -165,3 +169,77 @@ test('Recent allocations shows an empty message when the job has no allocations'
);
});
});

test('Active deployment can be promoted', function(assert) {
let job;
let deployment;

this.server.create('node');
const mirageJob = makeMirageJob(this.server, { activeDeployment: true });

this.store.findAll('job');

return wait()
.then(() => {
job = this.store.peekAll('job').findBy('plainId', mirageJob.id);
deployment = job.get('latestDeployment');

this.setProperties(commonProperties(job));
this.render(commonTemplate);

return wait();
})
.then(() => {
click('[data-test-promote-canary]');
return wait();
})
.then(() => {
const requests = this.server.pretender.handledRequests;
assert.ok(
requests
.filterBy('method', 'POST')
.findBy('url', `/v1/deployment/promote/${deployment.get('id')}`),
'A promote POST request was made'
);
});
});

test('When promoting the active deployment fails, an error is shown', function(assert) {
this.server.pretender.post('/v1/deployment/promote/:id', () => [403, {}, null]);

let job;

this.server.create('node');
const mirageJob = makeMirageJob(this.server, { activeDeployment: true });

this.store.findAll('job');

return wait()
.then(() => {
job = this.store.peekAll('job').findBy('plainId', mirageJob.id);

this.setProperties(commonProperties(job));
this.render(commonTemplate);

return wait();
})
.then(() => {
click('[data-test-promote-canary]');
return wait();
})
.then(() => {
assert.equal(
find('[data-test-job-error-title]').textContent,
'Could Not Promote Deployment',
'Appropriate error is shown'
);
assert.ok(
find('[data-test-job-error-body]').textContent.includes('ACL'),
'The error message mentions ACLs'
);

click('[data-test-job-error-close]');
assert.notOk(find('[data-test-job-error-title]'), 'Error message is dismissable');
return wait();
});
});

0 comments on commit 1f5e3a8

Please sign in to comment.