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

     1  import { module, test } from 'qunit';
     2  import { setupTest } from 'ember-qunit';
     3  import EvaluationModel from 'nomad-ui/models/evaluation';
     4  
     5  module('Unit | Serializer | Evaluation', function(hooks) {
     6    setupTest(hooks);
     7    hooks.beforeEach(function() {
     8      this.store = this.owner.lookup('service:store');
     9      this.subject = () => this.store.serializerFor('evaluation');
    10    });
    11  
    12    const sampleDate = new Date('2018-12-12T00:00:00');
    13    const normalizationTestCases = [
    14      {
    15        name: 'Normal',
    16        in: {
    17          ID: 'test-eval',
    18          CreateTime: +sampleDate * 1000000,
    19          ModifyTime: +sampleDate * 1000000,
    20          FailedTGAllocs: {
    21            taskGroup: {
    22              NodesAvailable: 10,
    23            },
    24          },
    25          JobID: 'some-job-id',
    26          Job: {
    27            Namespace: 'test-namespace',
    28          },
    29        },
    30        out: {
    31          data: {
    32            id: 'test-eval',
    33            type: 'evaluation',
    34            attributes: {
    35              createTime: sampleDate,
    36              modifyTime: sampleDate,
    37              failedTGAllocs: [
    38                {
    39                  name: 'taskGroup',
    40                  nodesAvailable: 10,
    41                },
    42              ],
    43            },
    44            relationships: {
    45              job: {
    46                data: {
    47                  id: '["some-job-id","test-namespace"]',
    48                  type: 'job',
    49                },
    50              },
    51            },
    52          },
    53        },
    54      },
    55  
    56      {
    57        name: 'Dots in task group names',
    58        in: {
    59          ID: 'test-eval',
    60          CreateTime: +sampleDate * 1000000,
    61          ModifyTime: +sampleDate * 1000000,
    62          FailedTGAllocs: {
    63            'one.two': {
    64              NodesAvailable: 10,
    65            },
    66            'three.four': {
    67              NodesAvailable: 25,
    68            },
    69          },
    70          JobID: 'some-job-id',
    71          Job: {
    72            Namespace: 'test-namespace',
    73          },
    74        },
    75        out: {
    76          data: {
    77            id: 'test-eval',
    78            type: 'evaluation',
    79            attributes: {
    80              modifyTime: sampleDate,
    81              createTime: sampleDate,
    82              failedTGAllocs: [
    83                {
    84                  name: 'one.two',
    85                  nodesAvailable: 10,
    86                },
    87                {
    88                  name: 'three.four',
    89                  nodesAvailable: 25,
    90                },
    91              ],
    92            },
    93            relationships: {
    94              job: {
    95                data: {
    96                  id: '["some-job-id","test-namespace"]',
    97                  type: 'job',
    98                },
    99              },
   100            },
   101          },
   102        },
   103      },
   104    ];
   105  
   106    normalizationTestCases.forEach(testCase => {
   107      test(`normalization: ${testCase.name}`, async function(assert) {
   108        assert.deepEqual(this.subject().normalize(EvaluationModel, testCase.in), testCase.out);
   109      });
   110    });
   111  });