github.com/hernad/nomad@v1.6.112/ui/tests/unit/serializers/scale-event-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 ScaleEventModel from 'nomad-ui/models/scale-event'; 9 10 module('Unit | Serializer | Scale Event', function (hooks) { 11 setupTest(hooks); 12 hooks.beforeEach(function () { 13 this.store = this.owner.lookup('service:store'); 14 this.subject = () => this.store.serializerFor('scale-event'); 15 }); 16 17 const sampleDate = new Date('2020-12-07T00:00:00'); 18 const normalizationTestCases = [ 19 { 20 name: 'Normal', 21 in: { 22 Count: null, 23 CreateIndex: 16, 24 Error: true, 25 EvalID: null, 26 Message: 'job scaling blocked due to active deployment', 27 Meta: { 28 OriginalCount: 3, 29 OriginalMessage: 'submitted using the Nomad CLI', 30 OriginalMeta: null, 31 }, 32 PreviousCount: 1, 33 Time: +sampleDate * 1000000, 34 }, 35 out: { 36 data: { 37 attributes: { 38 count: null, 39 error: true, 40 message: 'job scaling blocked due to active deployment', 41 meta: { 42 OriginalCount: 3, 43 OriginalMessage: 'submitted using the Nomad CLI', 44 OriginalMeta: null, 45 }, 46 previousCount: 1, 47 time: sampleDate, 48 timeNanos: 0, 49 }, 50 relationships: {}, 51 type: 'scale-event', 52 id: null, 53 }, 54 }, 55 }, 56 { 57 name: 'No meta', 58 in: { 59 Count: 3, 60 CreateIndex: 23, 61 Error: false, 62 EvalID: '753bb12c-345e-22b2-f0b4-17f84239b98b', 63 Message: 'submitted using the Nomad CLI', 64 Meta: null, 65 PreviousCount: 1, 66 Time: +sampleDate * 1000000, 67 }, 68 out: { 69 data: { 70 attributes: { 71 count: 3, 72 error: false, 73 message: 'submitted using the Nomad CLI', 74 meta: {}, 75 previousCount: 1, 76 time: sampleDate, 77 timeNanos: 0, 78 }, 79 relationships: {}, 80 type: 'scale-event', 81 id: null, 82 }, 83 }, 84 }, 85 ]; 86 87 normalizationTestCases.forEach((testCase) => { 88 test(`normalization: ${testCase.name}`, async function (assert) { 89 assert.deepEqual( 90 this.subject().normalize(ScaleEventModel, testCase.in), 91 testCase.out 92 ); 93 }); 94 }); 95 });