github.com/blixtra/nomad@v0.7.2-0.20171221000451-da9a1d7bb050/ui/tests/unit/serializers/job-test.js (about) 1 import { test } from 'ember-qunit'; 2 import JobModel from 'nomad-ui/models/job'; 3 import moduleForSerializer from '../../helpers/module-for-serializer'; 4 5 moduleForSerializer('job', 'Unit | Serializer | Job', { 6 needs: [ 7 'serializer:job', 8 'model:task-group-summary', 9 'model:task-group', 10 'transform:fragment-array', 11 ], 12 }); 13 14 test('The JobSummary object is transformed from a map to a list', function(assert) { 15 const original = { 16 ID: 'example', 17 ParentID: '', 18 Name: 'example', 19 Type: 'service', 20 Priority: 50, 21 Periodic: false, 22 ParameterizedJob: false, 23 Stop: false, 24 Status: 'running', 25 StatusDescription: '', 26 JobSummary: { 27 JobID: 'example', 28 Summary: { 29 cache: { 30 Queued: 0, 31 Complete: 0, 32 Failed: 0, 33 Running: 1, 34 Starting: 0, 35 Lost: 0, 36 }, 37 something_else: { 38 Queued: 0, 39 Complete: 0, 40 Failed: 0, 41 Running: 2, 42 Starting: 0, 43 Lost: 0, 44 }, 45 }, 46 CreateIndex: 7, 47 ModifyIndex: 13, 48 }, 49 CreateIndex: 7, 50 ModifyIndex: 9, 51 JobModifyIndex: 7, 52 }; 53 54 const { data } = this.subject().normalize(JobModel, original); 55 56 assert.deepEqual(data.attributes, { 57 name: 'example', 58 plainId: 'example', 59 type: 'service', 60 priority: 50, 61 periodic: false, 62 parameterized: false, 63 status: 'running', 64 statusDescription: '', 65 taskGroupSummaries: [ 66 { 67 name: 'cache', 68 queuedAllocs: 0, 69 completeAllocs: 0, 70 failedAllocs: 0, 71 runningAllocs: 1, 72 startingAllocs: 0, 73 lostAllocs: 0, 74 }, 75 { 76 name: 'something_else', 77 queuedAllocs: 0, 78 completeAllocs: 0, 79 failedAllocs: 0, 80 runningAllocs: 2, 81 startingAllocs: 0, 82 lostAllocs: 0, 83 }, 84 ], 85 createIndex: 7, 86 modifyIndex: 9, 87 }); 88 }); 89 90 test('The children stats are lifted out of the JobSummary object', function(assert) { 91 const original = { 92 ID: 'example', 93 ParentID: '', 94 Name: 'example', 95 Type: 'service', 96 Priority: 50, 97 Periodic: false, 98 ParameterizedJob: false, 99 Stop: false, 100 Status: 'running', 101 StatusDescription: '', 102 JobSummary: { 103 JobID: 'example', 104 Summary: {}, 105 Children: { 106 Pending: 1, 107 Running: 2, 108 Dead: 3, 109 }, 110 }, 111 CreateIndex: 7, 112 ModifyIndex: 9, 113 JobModifyIndex: 7, 114 }; 115 116 const normalized = this.subject().normalize(JobModel, original); 117 118 assert.deepEqual(normalized.data.attributes, { 119 name: 'example', 120 plainId: 'example', 121 type: 'service', 122 priority: 50, 123 periodic: false, 124 parameterized: false, 125 status: 'running', 126 statusDescription: '', 127 taskGroupSummaries: [], 128 pendingChildren: 1, 129 runningChildren: 2, 130 deadChildren: 3, 131 createIndex: 7, 132 modifyIndex: 9, 133 }); 134 }); 135 136 test('`default` is used as the namespace in the job ID when there is no namespace in the payload', function( 137 assert 138 ) { 139 const original = { 140 ID: 'example', 141 Name: 'example', 142 }; 143 144 const { data } = this.subject().normalize(JobModel, original); 145 assert.equal(data.id, JSON.stringify([data.attributes.name, 'default'])); 146 }); 147 148 test('The ID of the record is a composite of both the name and the namespace', function(assert) { 149 const original = { 150 ID: 'example', 151 Name: 'example', 152 Namespace: 'special-namespace', 153 }; 154 155 const { data } = this.subject().normalize(JobModel, original); 156 assert.equal( 157 data.id, 158 JSON.stringify([data.attributes.name, data.relationships.namespace.data.id]) 159 ); 160 });