github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/ui/tests/unit/adapters/allocation-test.js (about) 1 import { module, test } from 'qunit'; 2 import { setupTest } from 'ember-qunit'; 3 import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage'; 4 5 module('Unit | Adapter | Allocation', function(hooks) { 6 setupTest(hooks); 7 8 hooks.beforeEach(async function() { 9 this.store = this.owner.lookup('service:store'); 10 this.subject = () => this.store.adapterFor('allocation'); 11 12 this.server = startMirage(); 13 14 this.server.create('namespace'); 15 this.server.create('node'); 16 this.server.create('job', { createAllocations: false }); 17 this.server.create('allocation', { id: 'alloc-1' }); 18 }); 19 20 hooks.afterEach(function() { 21 this.server.shutdown(); 22 }); 23 24 test('`stop` makes the correct API call', async function(assert) { 25 const { pretender } = this.server; 26 const allocationId = 'alloc-1'; 27 28 const allocation = await this.store.findRecord('allocation', allocationId); 29 pretender.handledRequests.length = 0; 30 31 await this.subject().stop(allocation); 32 const req = pretender.handledRequests[0]; 33 assert.equal( 34 `${req.method} ${req.url}`, 35 `POST /v1/allocation/${allocationId}/stop`, 36 `POST /v1/allocation/${allocationId}/stop` 37 ); 38 }); 39 40 test('`restart` makes the correct API call', async function(assert) { 41 const { pretender } = this.server; 42 const allocationId = 'alloc-1'; 43 44 const allocation = await this.store.findRecord('allocation', allocationId); 45 pretender.handledRequests.length = 0; 46 47 await this.subject().restart(allocation); 48 const req = pretender.handledRequests[0]; 49 assert.equal( 50 `${req.method} ${req.url}`, 51 `PUT /v1/client/allocation/${allocationId}/restart`, 52 `PUT /v1/client/allocation/${allocationId}/restart` 53 ); 54 }); 55 56 test('`restart` takes an optional task name and makes the correct API call', async function(assert) { 57 const { pretender } = this.server; 58 const allocationId = 'alloc-1'; 59 const taskName = 'task-name'; 60 61 const allocation = await this.store.findRecord('allocation', allocationId); 62 pretender.handledRequests.length = 0; 63 64 await this.subject().restart(allocation, taskName); 65 const req = pretender.handledRequests[0]; 66 assert.equal( 67 `${req.method} ${req.url}`, 68 `PUT /v1/client/allocation/${allocationId}/restart`, 69 `PUT /v1/client/allocation/${allocationId}/restart` 70 ); 71 assert.deepEqual( 72 JSON.parse(req.requestBody), 73 { TaskName: taskName }, 74 'Request body is correct' 75 ); 76 }); 77 });