github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/tests/unit/serializers/job-summary-test.js (about)

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