github.com/hernad/nomad@v1.6.112/ui/tests/unit/serializers/deployment-test.js (about)

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  import { module, test } from 'qunit';
     7  import { setupTest } from 'ember-qunit';
     8  import DeploymentModel from 'nomad-ui/models/deployment';
     9  
    10  module('Unit | Serializer | Deployment', function (hooks) {
    11    setupTest(hooks);
    12    hooks.beforeEach(function () {
    13      this.store = this.owner.lookup('service:store');
    14      this.subject = () => this.store.serializerFor('deployment');
    15    });
    16  
    17    const normalizationTestCases = [
    18      {
    19        name: 'Normal',
    20        in: {
    21          ID: 'test-deployment',
    22          JobID: 'test-job',
    23          Namespace: 'test-namespace',
    24          Status: 'canceled',
    25          TaskGroups: {
    26            taskGroup: {
    27              DesiredCanaries: 2,
    28            },
    29          },
    30        },
    31        out: {
    32          data: {
    33            id: 'test-deployment',
    34            type: 'deployment',
    35            attributes: {
    36              status: 'canceled',
    37              taskGroupSummaries: [
    38                {
    39                  name: 'taskGroup',
    40                  desiredCanaries: 2,
    41                  placedCanaryAllocations: [],
    42                },
    43              ],
    44            },
    45            relationships: {
    46              allocations: {
    47                links: {
    48                  related: '/v1/deployment/allocations/test-deployment',
    49                },
    50              },
    51              job: {
    52                data: {
    53                  id: '["test-job","test-namespace"]',
    54                  type: 'job',
    55                },
    56              },
    57              jobForLatest: {
    58                data: {
    59                  id: '["test-job","test-namespace"]',
    60                  type: 'job',
    61                },
    62              },
    63            },
    64          },
    65        },
    66      },
    67  
    68      {
    69        name: 'Dots in task group names',
    70        in: {
    71          ID: 'test-deployment',
    72          JobID: 'test-job',
    73          Namespace: 'test-namespace',
    74          Status: 'canceled',
    75          TaskGroups: {
    76            'one.two': {
    77              DesiredCanaries: 2,
    78            },
    79            'three.four': {
    80              DesiredCanaries: 3,
    81            },
    82          },
    83        },
    84        out: {
    85          data: {
    86            id: 'test-deployment',
    87            type: 'deployment',
    88            attributes: {
    89              status: 'canceled',
    90              taskGroupSummaries: [
    91                {
    92                  name: 'one.two',
    93                  desiredCanaries: 2,
    94                  placedCanaryAllocations: [],
    95                },
    96                {
    97                  name: 'three.four',
    98                  desiredCanaries: 3,
    99                  placedCanaryAllocations: [],
   100                },
   101              ],
   102            },
   103            relationships: {
   104              allocations: {
   105                links: {
   106                  related: '/v1/deployment/allocations/test-deployment',
   107                },
   108              },
   109              job: {
   110                data: {
   111                  id: '["test-job","test-namespace"]',
   112                  type: 'job',
   113                },
   114              },
   115              jobForLatest: {
   116                data: {
   117                  id: '["test-job","test-namespace"]',
   118                  type: 'job',
   119                },
   120              },
   121            },
   122          },
   123        },
   124      },
   125    ];
   126  
   127    normalizationTestCases.forEach((testCase) => {
   128      test(`normalization: ${testCase.name}`, async function (assert) {
   129        assert.deepEqual(
   130          this.subject().normalize(DeploymentModel, testCase.in),
   131          testCase.out
   132        );
   133      });
   134    });
   135  });