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