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 job-summary serializer
This commit is contained in:
@@ -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(
|
||||
|
||||
103
ui/tests/unit/serializers/job-summary-test.js
Normal file
103
ui/tests/unit/serializers/job-summary-test.js
Normal 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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user