github.com/hernad/nomad@v1.6.112/ui/tests/unit/serializers/job-summary-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 JobSummaryModel from 'nomad-ui/models/job-summary';
     9  
    10  module('Unit | Serializer | JobSummary', function (hooks) {
    11    setupTest(hooks);
    12    hooks.beforeEach(function () {
    13      this.store = this.owner.lookup('service:store');
    14      this.subject = () => this.store.serializerFor('job-summary');
    15    });
    16  
    17    const normalizationTestCases = [
    18      {
    19        name: 'Normal',
    20        in: {
    21          JobID: 'test-summary',
    22          Namespace: 'test-namespace',
    23          Summary: {
    24            taskGroup: {
    25              Complete: 0,
    26              Running: 1,
    27            },
    28          },
    29        },
    30        out: {
    31          data: {
    32            id: '["test-summary","test-namespace"]',
    33            type: 'job-summary',
    34            attributes: {
    35              taskGroupSummaries: [
    36                {
    37                  name: 'taskGroup',
    38                  completeAllocs: 0,
    39                  runningAllocs: 1,
    40                },
    41              ],
    42            },
    43            relationships: {
    44              job: {
    45                data: {
    46                  id: '["test-summary","test-namespace"]',
    47                  type: 'job',
    48                },
    49              },
    50            },
    51          },
    52        },
    53      },
    54  
    55      {
    56        name: 'Dots in task group names',
    57        in: {
    58          JobID: 'test-summary',
    59          Namespace: 'test-namespace',
    60          Summary: {
    61            'one.two': {
    62              Complete: 0,
    63              Running: 1,
    64            },
    65            'three.four': {
    66              Failed: 2,
    67              Lost: 3,
    68            },
    69          },
    70        },
    71        out: {
    72          data: {
    73            id: '["test-summary","test-namespace"]',
    74            type: 'job-summary',
    75            attributes: {
    76              taskGroupSummaries: [
    77                {
    78                  name: 'one.two',
    79                  completeAllocs: 0,
    80                  runningAllocs: 1,
    81                },
    82                {
    83                  name: 'three.four',
    84                  failedAllocs: 2,
    85                  lostAllocs: 3,
    86                },
    87              ],
    88            },
    89            relationships: {
    90              job: {
    91                data: {
    92                  id: '["test-summary","test-namespace"]',
    93                  type: 'job',
    94                },
    95              },
    96            },
    97          },
    98        },
    99      },
   100    ];
   101  
   102    normalizationTestCases.forEach((testCase) => {
   103      test(`normalization: ${testCase.name}`, async function (assert) {
   104        assert.deepEqual(
   105          this.subject().normalize(JobSummaryModel, testCase.in),
   106          testCase.out
   107        );
   108      });
   109    });
   110  });