mirror of
https://github.com/kemko/nomad.git
synced 2026-01-08 19:35:41 +03:00
Don't use Ember.get in conjunction with dynamic strings in the evaluation serializer
This commit is contained in:
@@ -7,8 +7,10 @@ export default ApplicationSerializer.extend({
|
||||
system: service(),
|
||||
|
||||
normalize(typeHash, hash) {
|
||||
hash.FailedTGAllocs = Object.keys(hash.FailedTGAllocs || {}).map(key => {
|
||||
return assign({ Name: key }, get(hash, `FailedTGAllocs.${key}`) || {});
|
||||
const failures = hash.FailedTGAllocs || {};
|
||||
hash.FailedTGAllocs = Object.keys(failures).map(key => {
|
||||
const propertiesForKey = failures[key] || {};
|
||||
return assign({ Name: key }, propertiesForKey);
|
||||
});
|
||||
|
||||
hash.PlainJobId = hash.JobID;
|
||||
|
||||
104
ui/tests/unit/serializers/evaluation-test.js
Normal file
104
ui/tests/unit/serializers/evaluation-test.js
Normal file
@@ -0,0 +1,104 @@
|
||||
import { test } from 'ember-qunit';
|
||||
import EvaluationModel from 'nomad-ui/models/evaluation';
|
||||
import moduleForSerializer from '../../helpers/module-for-serializer';
|
||||
|
||||
moduleForSerializer('evaluation', 'Unit | Serializer | Evaluation', {
|
||||
needs: [
|
||||
'serializer:evaluation',
|
||||
'service:system',
|
||||
'transform:fragment-array',
|
||||
'model:job',
|
||||
'model:placement-failure',
|
||||
],
|
||||
});
|
||||
|
||||
const normalizationTestCases = [
|
||||
{
|
||||
name: 'Normal',
|
||||
in: {
|
||||
ID: 'test-eval',
|
||||
FailedTGAllocs: {
|
||||
taskGroup: {
|
||||
NodesAvailable: 10,
|
||||
},
|
||||
},
|
||||
JobID: 'some-job-id',
|
||||
Job: {
|
||||
Namespace: 'test-namespace',
|
||||
},
|
||||
},
|
||||
out: {
|
||||
data: {
|
||||
id: 'test-eval',
|
||||
type: 'evaluation',
|
||||
attributes: {
|
||||
failedTGAllocs: [
|
||||
{
|
||||
name: 'taskGroup',
|
||||
nodesAvailable: 10,
|
||||
},
|
||||
],
|
||||
},
|
||||
relationships: {
|
||||
job: {
|
||||
data: {
|
||||
id: '["some-job-id","test-namespace"]',
|
||||
type: 'job',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: 'Dots in task group names',
|
||||
in: {
|
||||
ID: 'test-eval',
|
||||
FailedTGAllocs: {
|
||||
'one.two': {
|
||||
NodesAvailable: 10,
|
||||
},
|
||||
'three.four': {
|
||||
NodesAvailable: 25,
|
||||
},
|
||||
},
|
||||
JobID: 'some-job-id',
|
||||
Job: {
|
||||
Namespace: 'test-namespace',
|
||||
},
|
||||
},
|
||||
out: {
|
||||
data: {
|
||||
id: 'test-eval',
|
||||
type: 'evaluation',
|
||||
attributes: {
|
||||
failedTGAllocs: [
|
||||
{
|
||||
name: 'one.two',
|
||||
nodesAvailable: 10,
|
||||
},
|
||||
{
|
||||
name: 'three.four',
|
||||
nodesAvailable: 25,
|
||||
},
|
||||
],
|
||||
},
|
||||
relationships: {
|
||||
job: {
|
||||
data: {
|
||||
id: '["some-job-id","test-namespace"]',
|
||||
type: 'job',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
normalizationTestCases.forEach(testCase => {
|
||||
test(`normalization: ${testCase.name}`, function(assert) {
|
||||
assert.deepEqual(this.subject().normalize(EvaluationModel, testCase.in), testCase.out);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user