Skip to content

Commit 8909046

Browse files
Don't use Ember.get in conjunction with dynamic strings in the job-plan serializer
1 parent f2b4fbc commit 8909046

File tree

2 files changed

+97
-3
lines changed

2 files changed

+97
-3
lines changed

ui/app/serializers/job-plan.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { get } from '@ember/object';
21
import { assign } from '@ember/polyfills';
32
import ApplicationSerializer from './application';
43

54
export default ApplicationSerializer.extend({
65
normalize(typeHash, hash) {
7-
hash.FailedTGAllocs = Object.keys(hash.FailedTGAllocs || {}).map(key => {
8-
return assign({ Name: key }, get(hash, `FailedTGAllocs.${key}`) || {});
6+
const failures = hash.FailedTGAllocs || {};
7+
hash.FailedTGAllocs = Object.keys(failures).map(key => {
8+
return assign({ Name: key }, failures[key] || {});
99
});
1010
return this._super(...arguments);
1111
},
+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import { test } from 'ember-qunit';
2+
import JobPlanModel from 'nomad-ui/models/job-plan';
3+
import moduleForSerializer from '../../helpers/module-for-serializer';
4+
5+
moduleForSerializer('job-plan', 'Unit | Serializer | JobPlan', {
6+
needs: [
7+
'service:token',
8+
'service:system',
9+
'serializer:job-plan',
10+
'transform:fragment-array',
11+
'model:placement-failure',
12+
],
13+
});
14+
15+
const normalizationTestCases = [
16+
{
17+
name: 'Normal',
18+
in: {
19+
ID: 'test-plan',
20+
Diff: {
21+
Arbitrary: 'Value',
22+
},
23+
FailedTGAllocs: {
24+
taskGroup: {
25+
NodesAvailable: 10,
26+
},
27+
},
28+
},
29+
out: {
30+
data: {
31+
id: 'test-plan',
32+
type: 'job-plan',
33+
attributes: {
34+
diff: {
35+
Arbitrary: 'Value',
36+
},
37+
failedTGAllocs: [
38+
{
39+
name: 'taskGroup',
40+
nodesAvailable: 10,
41+
},
42+
],
43+
},
44+
relationships: {},
45+
},
46+
},
47+
},
48+
49+
{
50+
name: 'Dots in task names',
51+
in: {
52+
ID: 'test-plan',
53+
Diff: {
54+
Arbitrary: 'Value',
55+
},
56+
FailedTGAllocs: {
57+
'one.two': {
58+
NodesAvailable: 10,
59+
},
60+
'three.four': {
61+
NodesAvailable: 25,
62+
},
63+
},
64+
},
65+
out: {
66+
data: {
67+
id: 'test-plan',
68+
type: 'job-plan',
69+
attributes: {
70+
diff: {
71+
Arbitrary: 'Value',
72+
},
73+
failedTGAllocs: [
74+
{
75+
name: 'one.two',
76+
nodesAvailable: 10,
77+
},
78+
{
79+
name: 'three.four',
80+
nodesAvailable: 25,
81+
},
82+
],
83+
},
84+
relationships: {},
85+
},
86+
},
87+
},
88+
];
89+
90+
normalizationTestCases.forEach(testCase => {
91+
test(`normalization: ${testCase.name}`, function(assert) {
92+
assert.deepEqual(this.subject().normalize(JobPlanModel, testCase.in), testCase.out);
93+
});
94+
});

0 commit comments

Comments
 (0)