github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/ui/tests/unit/serializers/job-plan-test.js (about)

     1  import { module, test } from 'qunit';
     2  import { setupTest } from 'ember-qunit';
     3  import JobPlanModel from 'nomad-ui/models/job-plan';
     4  
     5  module('Unit | Serializer | JobPlan', function(hooks) {
     6    setupTest(hooks);
     7    hooks.beforeEach(function() {
     8      this.store = this.owner.lookup('service:store');
     9      this.subject = () => this.store.serializerFor('job-plan');
    10    });
    11  
    12    const normalizationTestCases = [
    13      {
    14        name: 'Normal',
    15        in: {
    16          ID: 'test-plan',
    17          Diff: {
    18            Arbitrary: 'Value',
    19          },
    20          FailedTGAllocs: {
    21            taskGroup: {
    22              NodesAvailable: 10,
    23            },
    24          },
    25        },
    26        out: {
    27          data: {
    28            id: 'test-plan',
    29            type: 'job-plan',
    30            attributes: {
    31              diff: {
    32                Arbitrary: 'Value',
    33              },
    34              failedTGAllocs: [
    35                {
    36                  name: 'taskGroup',
    37                  nodesAvailable: 10,
    38                },
    39              ],
    40            },
    41            relationships: {
    42              preemptions: {
    43                data: [],
    44              },
    45            },
    46          },
    47        },
    48      },
    49  
    50      {
    51        name: 'Dots in task names',
    52        in: {
    53          ID: 'test-plan',
    54          Diff: {
    55            Arbitrary: 'Value',
    56          },
    57          FailedTGAllocs: {
    58            'one.two': {
    59              NodesAvailable: 10,
    60            },
    61            'three.four': {
    62              NodesAvailable: 25,
    63            },
    64          },
    65        },
    66        out: {
    67          data: {
    68            id: 'test-plan',
    69            type: 'job-plan',
    70            attributes: {
    71              diff: {
    72                Arbitrary: 'Value',
    73              },
    74              failedTGAllocs: [
    75                {
    76                  name: 'one.two',
    77                  nodesAvailable: 10,
    78                },
    79                {
    80                  name: 'three.four',
    81                  nodesAvailable: 25,
    82                },
    83              ],
    84            },
    85            relationships: {
    86              preemptions: {
    87                data: [],
    88              },
    89            },
    90          },
    91        },
    92      },
    93  
    94      {
    95        name: 'With preemptions',
    96        in: {
    97          ID: 'test-plan',
    98          Diff: {
    99            Arbitrary: 'Value',
   100          },
   101          FailedTGAllocs: {
   102            task: {
   103              NodesAvailable: 10,
   104            },
   105          },
   106          Annotations: {
   107            PreemptedAllocs: [
   108              { ID: 'preemption-one-allocation' },
   109              { ID: 'preemption-two-allocation' },
   110            ],
   111          },
   112        },
   113        out: {
   114          data: {
   115            id: 'test-plan',
   116            type: 'job-plan',
   117            attributes: {
   118              diff: {
   119                Arbitrary: 'Value',
   120              },
   121              failedTGAllocs: [
   122                {
   123                  name: 'task',
   124                  nodesAvailable: 10,
   125                },
   126              ],
   127            },
   128            relationships: {
   129              preemptions: {
   130                data: [
   131                  { id: 'preemption-one-allocation', type: 'allocation' },
   132                  { id: 'preemption-two-allocation', type: 'allocation' },
   133                ],
   134              },
   135            },
   136          },
   137        },
   138      },
   139    ];
   140  
   141    normalizationTestCases.forEach(testCase => {
   142      test(`normalization: ${testCase.name}`, async function(assert) {
   143        assert.deepEqual(this.subject().normalize(JobPlanModel, testCase.in), testCase.out);
   144      });
   145    });
   146  });