From 08bd43505278dcd5d2ef31e77aaf1811a24d26d1 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Mon, 20 Jul 2020 21:05:44 -0700 Subject: [PATCH] Test region query param for job adapter actions --- ui/tests/unit/adapters/job-test.js | 107 +++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/ui/tests/unit/adapters/job-test.js b/ui/tests/unit/adapters/job-test.js index 9913a0761..315c0a605 100644 --- a/ui/tests/unit/adapters/job-test.js +++ b/ui/tests/unit/adapters/job-test.js @@ -44,6 +44,17 @@ module('Unit | Adapter | Job', function(hooks) { // namespaces request everywhere. this.server.pretender.handledRequests.length = 0; }; + + this.initializeWithJob = async (props = {}) => { + await this.initializeUI(props); + + const job = await this.store.findRecord( + 'job', + JSON.stringify(['job-1', props.namespace || 'default']) + ); + this.server.pretender.handledRequests.length = 0; + return job; + }; }); hooks.afterEach(function() { @@ -437,6 +448,102 @@ module('Unit | Adapter | Job', function(hooks) { 'No requests include the region query param' ); }); + + test('fetchRawDefinition requests include the activeRegion', async function(assert) { + const region = 'region-2'; + const job = await this.initializeWithJob({ region }); + + await this.subject().fetchRawDefinition(job); + + const request = this.server.pretender.handledRequests[0]; + assert.equal(request.url, `/v1/job/${job.plainId}?region=${region}`); + assert.equal(request.method, 'GET'); + }); + + test('forcePeriodic requests include the activeRegion', async function(assert) { + const region = 'region-2'; + const job = await this.initializeWithJob({ region }); + job.set('periodic', true); + + await this.subject().forcePeriodic(job); + + const request = this.server.pretender.handledRequests[0]; + assert.equal(request.url, `/v1/job/${job.plainId}/periodic/force?region=${region}`); + assert.equal(request.method, 'POST'); + }); + + test('stop requests include the activeRegion', async function(assert) { + const region = 'region-2'; + const job = await this.initializeWithJob({ region }); + + await this.subject().stop(job); + + const request = this.server.pretender.handledRequests[0]; + assert.equal(request.url, `/v1/job/${job.plainId}?region=${region}`); + assert.equal(request.method, 'DELETE'); + }); + + test('parse requests include the activeRegion', async function(assert) { + const region = 'region-2'; + await this.initializeUI({ region }); + + await this.subject().parse('job "name-goes-here" {'); + + const request = this.server.pretender.handledRequests[0]; + assert.equal(request.url, `/v1/jobs/parse?region=${region}`); + assert.equal(request.method, 'POST'); + assert.deepEqual(JSON.parse(request.requestBody), { + JobHCL: 'job "name-goes-here" {', + Canonicalize: true, + }); + }); + + test('plan requests include the activeRegion', async function(assert) { + const region = 'region-2'; + const job = await this.initializeWithJob({ region }); + job.set('_newDefinitionJSON', {}); + + await this.subject().plan(job); + + const request = this.server.pretender.handledRequests[0]; + assert.equal(request.url, `/v1/job/${job.plainId}/plan?region=${region}`); + assert.equal(request.method, 'POST'); + }); + + test('run requests include the activeRegion', async function(assert) { + const region = 'region-2'; + const job = await this.initializeWithJob({ region }); + job.set('_newDefinitionJSON', {}); + + await this.subject().run(job); + + const request = this.server.pretender.handledRequests[0]; + assert.equal(request.url, `/v1/jobs?region=${region}`); + assert.equal(request.method, 'POST'); + }); + + test('update requests include the activeRegion', async function(assert) { + const region = 'region-2'; + const job = await this.initializeWithJob({ region }); + job.set('_newDefinitionJSON', {}); + + await this.subject().update(job); + + const request = this.server.pretender.handledRequests[0]; + assert.equal(request.url, `/v1/job/${job.plainId}?region=${region}`); + assert.equal(request.method, 'POST'); + }); + + test('scale requests include the activeRegion', async function(assert) { + const region = 'region-2'; + const job = await this.initializeWithJob({ region }); + + await this.subject().scale(job, 'group-1', 5, 'Reason: a test'); + + const request = this.server.pretender.handledRequests[0]; + assert.equal(request.url, `/v1/job/${job.plainId}/scale?region=${region}`); + assert.equal(request.method, 'POST'); + }); }); function makeMockModel(id, options) {