From 27c16d1f0ab4dc0fcf382c45a87f40dc69a153e0 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Mon, 7 Dec 2020 12:28:47 -0800 Subject: [PATCH] Test coverage for the scale event serializer --- ui/tests/unit/serializers/scale-event-test.js | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 ui/tests/unit/serializers/scale-event-test.js diff --git a/ui/tests/unit/serializers/scale-event-test.js b/ui/tests/unit/serializers/scale-event-test.js new file mode 100644 index 000000000..c6d8c1806 --- /dev/null +++ b/ui/tests/unit/serializers/scale-event-test.js @@ -0,0 +1,87 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; +import ScaleEventModel from 'nomad-ui/models/scale-event'; + +module('Unit | Serializer | Scale Event', function(hooks) { + setupTest(hooks); + hooks.beforeEach(function() { + this.store = this.owner.lookup('service:store'); + this.subject = () => this.store.serializerFor('scale-event'); + }); + + const sampleDate = new Date('2020-12-07T00:00:00'); + const normalizationTestCases = [ + { + name: 'Normal', + in: { + Count: null, + CreateIndex: 16, + Error: true, + EvalID: null, + Message: 'job scaling blocked due to active deployment', + Meta: { + OriginalCount: 3, + OriginalMessage: 'submitted using the Nomad CLI', + OriginalMeta: null, + }, + PreviousCount: 1, + Time: +sampleDate * 1000000, + }, + out: { + data: { + attributes: { + count: null, + error: true, + message: 'job scaling blocked due to active deployment', + meta: { + OriginalCount: 3, + OriginalMessage: 'submitted using the Nomad CLI', + OriginalMeta: null, + }, + previousCount: 1, + time: sampleDate, + timeNanos: 0, + }, + relationships: {}, + type: 'scale-event', + id: null, + }, + }, + }, + { + name: 'No meta', + in: { + Count: 3, + CreateIndex: 23, + Error: false, + EvalID: '753bb12c-345e-22b2-f0b4-17f84239b98b', + Message: 'submitted using the Nomad CLI', + Meta: null, + PreviousCount: 1, + Time: +sampleDate * 1000000, + }, + out: { + data: { + attributes: { + count: 3, + error: false, + message: 'submitted using the Nomad CLI', + meta: {}, + previousCount: 1, + time: sampleDate, + timeNanos: 0, + }, + relationships: {}, + type: 'scale-event', + id: null, + }, + }, + }, + ]; + + normalizationTestCases.forEach(testCase => { + test(`normalization: ${testCase.name}`, async function(assert) { + assert.deepEqual(this.subject().normalize(ScaleEventModel, testCase.in), testCase.out); + }); + }); +});