diff --git a/ui/app/serializers/deployment.js b/ui/app/serializers/deployment.js index 0e39f9536..456eb1b25 100644 --- a/ui/app/serializers/deployment.js +++ b/ui/app/serializers/deployment.js @@ -9,8 +9,9 @@ export default ApplicationSerializer.extend({ normalize(typeHash, hash) { if (hash) { - hash.TaskGroupSummaries = Object.keys(get(hash, 'TaskGroups') || {}).map(key => { - const deploymentStats = get(hash, `TaskGroups.${key}`); + const taskGroups = hash.TaskGroups || {}; + hash.TaskGroupSummaries = Object.keys(taskGroups).map(key => { + const deploymentStats = taskGroups[key]; return assign({ Name: key }, deploymentStats); }); diff --git a/ui/tests/unit/serializers/deployment-test.js b/ui/tests/unit/serializers/deployment-test.js new file mode 100644 index 000000000..04605160f --- /dev/null +++ b/ui/tests/unit/serializers/deployment-test.js @@ -0,0 +1,129 @@ +import { test } from 'ember-qunit'; +import DeploymentModel from 'nomad-ui/models/deployment'; +import moduleForSerializer from '../../helpers/module-for-serializer'; + +moduleForSerializer('deployment', 'Unit | Serializer | Deployment', { + needs: [ + 'adapter:application', + 'serializer:deployment', + 'service:system', + 'service:token', + 'transform:fragment-array', + 'model:allocation', + 'model:job', + 'model:task-group-deployment-summary', + ], +}); + +const normalizationTestCases = [ + { + name: 'Normal', + in: { + ID: 'test-deployment', + JobID: 'test-job', + Namespace: 'test-namespace', + Status: 'canceled', + TaskGroups: { + taskGroup: { + DesiredCanaries: 2, + }, + }, + }, + out: { + data: { + id: 'test-deployment', + type: 'deployment', + attributes: { + status: 'canceled', + taskGroupSummaries: [ + { + name: 'taskGroup', + desiredCanaries: 2, + }, + ], + }, + relationships: { + allocations: { + links: { + related: '/v1/deployment/allocations/test-deployment', + }, + }, + job: { + data: { + id: '["test-job","test-namespace"]', + type: 'job', + }, + }, + jobForLatest: { + data: { + id: '["test-job","test-namespace"]', + type: 'job', + }, + }, + }, + }, + }, + }, + + { + name: 'Dots in task group names', + in: { + ID: 'test-deployment', + JobID: 'test-job', + Namespace: 'test-namespace', + Status: 'canceled', + TaskGroups: { + 'one.two': { + DesiredCanaries: 2, + }, + 'three.four': { + DesiredCanaries: 3, + }, + }, + }, + out: { + data: { + id: 'test-deployment', + type: 'deployment', + attributes: { + status: 'canceled', + taskGroupSummaries: [ + { + name: 'one.two', + desiredCanaries: 2, + }, + { + name: 'three.four', + desiredCanaries: 3, + }, + ], + }, + relationships: { + allocations: { + links: { + related: '/v1/deployment/allocations/test-deployment', + }, + }, + job: { + data: { + id: '["test-job","test-namespace"]', + type: 'job', + }, + }, + jobForLatest: { + data: { + id: '["test-job","test-namespace"]', + type: 'job', + }, + }, + }, + }, + }, + }, +]; + +normalizationTestCases.forEach(testCase => { + test(`normalization: ${testCase.name}`, function(assert) { + assert.deepEqual(this.subject().normalize(DeploymentModel, testCase.in), testCase.out); + }); +});