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