Don't use Ember.get in conjunction with dynamic strings in the job-summary serializer

This commit is contained in:
Michael Lange
2018-12-12 16:24:57 -08:00
parent 7143b3048b
commit 3a07f68d4f
2 changed files with 106 additions and 2 deletions

View File

@@ -9,8 +9,9 @@ export default ApplicationSerializer.extend({
hash.ID = JSON.stringify([hash.JobID, hash.Namespace || 'default']);
hash.JobID = hash.ID;
hash.TaskGroupSummaries = Object.keys(get(hash, 'Summary') || {}).map(key => {
const allocStats = get(hash, `Summary.${key}`) || {};
const fullSummary = hash.Summary || {};
hash.TaskGroupSummaries = Object.keys(fullSummary).map(key => {
const allocStats = fullSummary[key] || {};
const summary = { Name: key };
Object.keys(allocStats).forEach(

View File

@@ -0,0 +1,103 @@
import { test } from 'ember-qunit';
import JobSummaryModel from 'nomad-ui/models/job-summary';
import moduleForSerializer from '../../helpers/module-for-serializer';
moduleForSerializer('job-summary', 'Unit | Serializer | JobSummary', {
needs: [
'serializer:job-summary',
'transform:fragment-array',
'model:job',
'model:task-group-summary',
],
});
const normalizationTestCases = [
{
name: 'Normal',
in: {
JobID: 'test-summary',
Namespace: 'test-namespace',
Summary: {
taskGroup: {
Complete: 0,
Running: 1,
},
},
},
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',
},
},
},
},
},
},
{
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,
},
},
},
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',
},
},
},
},
},
},
];
normalizationTestCases.forEach(testCase => {
test(`normalization: ${testCase.name}`, function(assert) {
assert.deepEqual(this.subject().normalize(JobSummaryModel, testCase.in), testCase.out);
});
});