github.com/hernad/nomad@v1.6.112/ui/tests/unit/serializers/recommendation-summary-test.js (about) 1 /** 2 * Copyright (c) HashiCorp, Inc. 3 * SPDX-License-Identifier: MPL-2.0 4 */ 5 6 import { module, test } from 'qunit'; 7 import { setupTest } from 'ember-qunit'; 8 import RecommendationSummaryModel from 'nomad-ui/models/recommendation-summary'; 9 10 module('Unit | Serializer | RecommendationSummary', function (hooks) { 11 setupTest(hooks); 12 hooks.beforeEach(function () { 13 this.store = this.owner.lookup('service:store'); 14 this.subject = () => this.store.serializerFor('recommendation-summary'); 15 }); 16 17 const normalizationTestCases = [ 18 { 19 name: 'Normal', 20 in: [ 21 { 22 ID: '2345', 23 JobID: 'job-id', 24 Namespace: 'default', 25 Region: 'us-east-1', 26 Group: 'group-1', 27 Task: 'task-1', 28 Resource: 'MemoryMB', 29 Value: 500, 30 Current: 1000, 31 Stats: { 32 min: 25.0, 33 max: 575.0, 34 mean: 425.0, 35 media: 40.0, 36 }, 37 SubmitTime: 1600000002000000000, 38 }, 39 { 40 ID: '1234', 41 JobID: 'job-id', 42 Namespace: 'default', 43 Region: 'us-east-1', 44 Group: 'group-1', 45 Task: 'task-1', 46 Resource: 'CPU', 47 Value: 500, 48 Current: 1000, 49 Stats: { 50 min: 25.0, 51 max: 575.0, 52 mean: 425.0, 53 media: 40.0, 54 }, 55 SubmitTime: 1600000001000000000, 56 }, 57 { 58 ID: '6789', 59 JobID: 'other-job-id', 60 Namespace: 'other', 61 Region: 'us-east-1', 62 Group: 'group-2', 63 Task: 'task-2', 64 Resource: 'MemoryMB', 65 Value: 500, 66 Current: 1000, 67 Stats: { 68 min: 25.0, 69 max: 575.0, 70 mean: 425.0, 71 media: 40.0, 72 }, 73 SubmitTime: 1600000003000000000, 74 }, 75 ], 76 out: { 77 data: [ 78 { 79 attributes: { 80 jobId: 'job-id', 81 jobNamespace: 'default', 82 submitTime: new Date(1600000002000), 83 taskGroupName: 'group-1', 84 }, 85 id: '1234-2345', 86 relationships: { 87 job: { 88 data: { 89 id: '["job-id","default"]', 90 type: 'job', 91 }, 92 }, 93 recommendations: { 94 data: [ 95 { 96 id: '2345', 97 type: 'recommendation', 98 }, 99 { 100 id: '1234', 101 type: 'recommendation', 102 }, 103 ], 104 }, 105 }, 106 type: 'recommendation-summary', 107 }, 108 { 109 attributes: { 110 jobId: 'other-job-id', 111 jobNamespace: 'other', 112 submitTime: new Date(1600000003000), 113 taskGroupName: 'group-2', 114 }, 115 id: '6789', 116 relationships: { 117 job: { 118 data: { 119 id: '["other-job-id","other"]', 120 type: 'job', 121 }, 122 }, 123 recommendations: { 124 data: [ 125 { 126 id: '6789', 127 type: 'recommendation', 128 }, 129 ], 130 }, 131 }, 132 type: 'recommendation-summary', 133 }, 134 ], 135 included: [ 136 { 137 attributes: { 138 resource: 'MemoryMB', 139 stats: { 140 max: 575, 141 mean: 425, 142 media: 40, 143 min: 25, 144 }, 145 submitTime: new Date(1600000002000), 146 taskName: 'task-1', 147 value: 500, 148 }, 149 id: '2345', 150 relationships: { 151 job: { 152 links: { 153 related: '/v1/job/job-id', 154 }, 155 }, 156 }, 157 type: 'recommendation', 158 }, 159 { 160 attributes: { 161 resource: 'CPU', 162 stats: { 163 max: 575, 164 mean: 425, 165 media: 40, 166 min: 25, 167 }, 168 submitTime: new Date(1600000001000), 169 taskName: 'task-1', 170 value: 500, 171 }, 172 id: '1234', 173 relationships: { 174 job: { 175 links: { 176 related: '/v1/job/job-id', 177 }, 178 }, 179 }, 180 type: 'recommendation', 181 }, 182 { 183 attributes: { 184 resource: 'MemoryMB', 185 stats: { 186 max: 575, 187 mean: 425, 188 media: 40, 189 min: 25, 190 }, 191 submitTime: new Date(1600000003000), 192 taskName: 'task-2', 193 value: 500, 194 }, 195 id: '6789', 196 relationships: { 197 job: { 198 links: { 199 related: '/v1/job/other-job-id?namespace=other', 200 }, 201 }, 202 }, 203 type: 'recommendation', 204 }, 205 ], 206 }, 207 }, 208 ]; 209 210 normalizationTestCases.forEach((testCase) => { 211 test(`normalization: ${testCase.name}`, async function (assert) { 212 assert.deepEqual( 213 this.subject().normalizeArrayResponse( 214 this.store, 215 RecommendationSummaryModel, 216 testCase.in 217 ), 218 testCase.out 219 ); 220 }); 221 }); 222 });