github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/tests/unit/models/allocation-test.js (about) 1 import { run } from '@ember/runloop'; 2 import { module, test } from 'qunit'; 3 import { setupTest } from 'ember-qunit'; 4 5 module('Unit | Model | allocation', function(hooks) { 6 setupTest(hooks); 7 hooks.beforeEach(function() { 8 this.store = this.owner.lookup('service:store'); 9 }); 10 11 test("When the allocation's job version matches the job's version, the task group comes from the job.", function(assert) { 12 const job = run(() => 13 this.store.createRecord('job', { 14 name: 'this-job', 15 version: 1, 16 taskGroups: [ 17 { 18 name: 'from-job', 19 count: 1, 20 task: [], 21 }, 22 ], 23 }) 24 ); 25 26 const allocation = run(() => 27 this.store.createRecord('allocation', { 28 job, 29 jobVersion: 1, 30 taskGroupName: 'from-job', 31 allocationTaskGroup: { 32 name: 'from-allocation', 33 count: 1, 34 task: [], 35 }, 36 }) 37 ); 38 39 assert.equal(allocation.get('taskGroup.name'), 'from-job'); 40 }); 41 42 test("When the allocation's job version does not match the job's version, the task group comes from the alloc.", function(assert) { 43 const job = run(() => 44 this.store.createRecord('job', { 45 name: 'this-job', 46 version: 1, 47 taskGroups: [ 48 { 49 name: 'from-job', 50 count: 1, 51 task: [], 52 }, 53 ], 54 }) 55 ); 56 57 const allocation = run(() => 58 this.store.createRecord('allocation', { 59 job, 60 jobVersion: 2, 61 taskGroupName: 'from-job', 62 allocationTaskGroup: { 63 name: 'from-allocation', 64 count: 1, 65 task: [], 66 }, 67 }) 68 ); 69 70 assert.equal(allocation.get('taskGroup.name'), 'from-allocation'); 71 }); 72 73 test("When the allocation's job version does not match the job's version and the allocation has no task group, then task group is null", async function(assert) { 74 const job = run(() => 75 this.store.createRecord('job', { 76 name: 'this-job', 77 version: 1, 78 taskGroups: [ 79 { 80 name: 'from-job', 81 count: 1, 82 task: [], 83 }, 84 ], 85 }) 86 ); 87 88 const allocation = run(() => 89 this.store.createRecord('allocation', { 90 job, 91 jobVersion: 2, 92 taskGroupName: 'from-job', 93 }) 94 ); 95 96 assert.equal(allocation.get('taskGroup.name'), null); 97 }); 98 });