2019-03-14 02:17:12 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupTest } from 'ember-qunit';
|
2018-12-13 00:24:57 +00:00
|
|
|
import JobSummaryModel from 'nomad-ui/models/job-summary';
|
|
|
|
|
2019-03-14 02:17:12 +00:00
|
|
|
module('Unit | Serializer | JobSummary', function(hooks) {
|
|
|
|
setupTest(hooks);
|
|
|
|
hooks.beforeEach(function() {
|
|
|
|
this.store = this.owner.lookup('service:store');
|
|
|
|
this.subject = () => this.store.serializerFor('job-summary');
|
|
|
|
});
|
2018-12-13 00:24:57 +00:00
|
|
|
|
2019-03-14 02:17:12 +00:00
|
|
|
const normalizationTestCases = [
|
|
|
|
{
|
|
|
|
name: 'Normal',
|
|
|
|
in: {
|
|
|
|
JobID: 'test-summary',
|
|
|
|
Namespace: 'test-namespace',
|
|
|
|
Summary: {
|
|
|
|
taskGroup: {
|
|
|
|
Complete: 0,
|
|
|
|
Running: 1,
|
|
|
|
},
|
2018-12-13 00:24:57 +00:00
|
|
|
},
|
|
|
|
},
|
2019-03-14 02:17:12 +00:00
|
|
|
out: {
|
|
|
|
data: {
|
|
|
|
id: '["test-summary","test-namespace"]',
|
|
|
|
type: 'job-summary',
|
|
|
|
attributes: {
|
|
|
|
taskGroupSummaries: [
|
|
|
|
{
|
|
|
|
name: 'taskGroup',
|
|
|
|
completeAllocs: 0,
|
|
|
|
runningAllocs: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
relationships: {
|
|
|
|
job: {
|
|
|
|
data: {
|
|
|
|
id: '["test-summary","test-namespace"]',
|
|
|
|
type: 'job',
|
|
|
|
},
|
2018-12-13 00:24:57 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2019-03-14 02:17:12 +00:00
|
|
|
{
|
|
|
|
name: 'Dots in task group names',
|
|
|
|
in: {
|
|
|
|
JobID: 'test-summary',
|
|
|
|
Namespace: 'test-namespace',
|
|
|
|
Summary: {
|
|
|
|
'one.two': {
|
|
|
|
Complete: 0,
|
|
|
|
Running: 1,
|
|
|
|
},
|
|
|
|
'three.four': {
|
|
|
|
Failed: 2,
|
|
|
|
Lost: 3,
|
|
|
|
},
|
2018-12-13 00:24:57 +00:00
|
|
|
},
|
|
|
|
},
|
2019-03-14 02:17:12 +00:00
|
|
|
out: {
|
|
|
|
data: {
|
|
|
|
id: '["test-summary","test-namespace"]',
|
|
|
|
type: 'job-summary',
|
|
|
|
attributes: {
|
|
|
|
taskGroupSummaries: [
|
|
|
|
{
|
|
|
|
name: 'one.two',
|
|
|
|
completeAllocs: 0,
|
|
|
|
runningAllocs: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'three.four',
|
|
|
|
failedAllocs: 2,
|
|
|
|
lostAllocs: 3,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
relationships: {
|
|
|
|
job: {
|
|
|
|
data: {
|
|
|
|
id: '["test-summary","test-namespace"]',
|
|
|
|
type: 'job',
|
|
|
|
},
|
2018-12-13 00:24:57 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-03-14 02:17:12 +00:00
|
|
|
];
|
2018-12-13 00:24:57 +00:00
|
|
|
|
2019-03-14 02:17:12 +00:00
|
|
|
normalizationTestCases.forEach(testCase => {
|
2019-03-14 18:35:46 +00:00
|
|
|
test(`normalization: ${testCase.name}`, async function(assert) {
|
2019-03-14 02:17:12 +00:00
|
|
|
assert.deepEqual(this.subject().normalize(JobSummaryModel, testCase.in), testCase.out);
|
|
|
|
});
|
2018-12-13 00:24:57 +00:00
|
|
|
});
|
|
|
|
});
|