github.com/hernad/nomad@v1.6.112/ui/tests/unit/serializers/evaluation-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 EvaluationModel from 'nomad-ui/models/evaluation'; 9 10 module('Unit | Serializer | Evaluation', function (hooks) { 11 setupTest(hooks); 12 hooks.beforeEach(function () { 13 this.store = this.owner.lookup('service:store'); 14 this.subject = () => this.store.serializerFor('evaluation'); 15 }); 16 17 const sampleDate = new Date('2018-12-12T00:00:00'); 18 const normalizationTestCases = [ 19 { 20 name: 'Normal', 21 in: { 22 ID: 'test-eval', 23 CreateTime: +sampleDate * 1000000, 24 ModifyTime: +sampleDate * 1000000, 25 FailedTGAllocs: { 26 taskGroup: { 27 NodesAvailable: 10, 28 }, 29 }, 30 JobID: 'some-job-id', 31 Job: { 32 Namespace: 'test-namespace', 33 }, 34 }, 35 out: { 36 data: { 37 id: 'test-eval', 38 type: 'evaluation', 39 attributes: { 40 createTime: sampleDate, 41 modifyTime: sampleDate, 42 failedTGAllocs: [ 43 { 44 name: 'taskGroup', 45 nodesAvailable: 10, 46 }, 47 ], 48 namespace: 'test-namespace', 49 plainJobId: 'some-job-id', 50 }, 51 relationships: { 52 job: { 53 data: { 54 id: '["some-job-id","test-namespace"]', 55 type: 'job', 56 }, 57 }, 58 }, 59 }, 60 }, 61 }, 62 63 { 64 name: 'Dots in task group names', 65 in: { 66 ID: 'test-eval', 67 CreateTime: +sampleDate * 1000000, 68 ModifyTime: +sampleDate * 1000000, 69 FailedTGAllocs: { 70 'one.two': { 71 NodesAvailable: 10, 72 }, 73 'three.four': { 74 NodesAvailable: 25, 75 }, 76 }, 77 JobID: 'some-job-id', 78 Job: { 79 Namespace: 'test-namespace', 80 }, 81 }, 82 out: { 83 data: { 84 id: 'test-eval', 85 type: 'evaluation', 86 attributes: { 87 modifyTime: sampleDate, 88 createTime: sampleDate, 89 failedTGAllocs: [ 90 { 91 name: 'one.two', 92 nodesAvailable: 10, 93 }, 94 { 95 name: 'three.four', 96 nodesAvailable: 25, 97 }, 98 ], 99 namespace: 'test-namespace', 100 plainJobId: 'some-job-id', 101 }, 102 relationships: { 103 job: { 104 data: { 105 id: '["some-job-id","test-namespace"]', 106 type: 'job', 107 }, 108 }, 109 }, 110 }, 111 }, 112 }, 113 ]; 114 115 normalizationTestCases.forEach((testCase) => { 116 test(`normalization: ${testCase.name}`, async function (assert) { 117 assert.deepEqual( 118 this.subject().normalize(EvaluationModel, testCase.in), 119 testCase.out 120 ); 121 }); 122 }); 123 });