open-nomad/ui/tests/unit/serializers/deployment-test.js

128 lines
3.2 KiB
JavaScript
Raw Normal View History

import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import DeploymentModel from 'nomad-ui/models/deployment';
2021-12-28 14:45:20 +00:00
module('Unit | Serializer | Deployment', function (hooks) {
setupTest(hooks);
2021-12-28 14:45:20 +00:00
hooks.beforeEach(function () {
this.store = this.owner.lookup('service:store');
this.subject = () => this.store.serializerFor('deployment');
});
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,
placedCanaryAllocations: [],
},
],
},
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,
placedCanaryAllocations: [],
},
{
name: 'three.four',
desiredCanaries: 3,
placedCanaryAllocations: [],
},
],
},
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',
},
},
},
},
},
},
];
2021-12-28 14:45:20 +00:00
normalizationTestCases.forEach((testCase) => {
test(`normalization: ${testCase.name}`, async function (assert) {
assert.deepEqual(this.subject().normalize(DeploymentModel, testCase.in), testCase.out);
});
});
});