github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/tests/integration/data-modeling/related-evaluations-test.js (about)

     1  import { setupMirage } from 'ember-cli-mirage/test-support';
     2  import { module, test } from 'qunit';
     3  import { setupTest } from 'ember-qunit';
     4  
     5  module('Integration | Data Modeling | related evaluations', function (hooks) {
     6    setupTest(hooks);
     7    setupMirage(hooks);
     8  
     9    test('it should a return a list of related evaluations when the related query parameter is specified', async function (assert) {
    10      assert.expect(2);
    11      const store = this.owner.lookup('service:store');
    12  
    13      server.get('/evaluation/:id', function (_, fakeRes) {
    14        assert.equal(
    15          fakeRes.queryParams.related,
    16          'true',
    17          'it should append the related query parameter when making the API request for related evaluations'
    18        );
    19        return {
    20          ID: 'tomster',
    21          Priority: 50,
    22          Type: 'service',
    23          TriggeredBy: 'job-register',
    24          JobID: 'example',
    25          JobModifyIndex: 52,
    26          NodeID: 'yes',
    27          NodeModifyIndex: 0,
    28          Status: 'complete',
    29          StatusDescription: '',
    30          Wait: 0,
    31          NextEval: '',
    32          PreviousEval: '',
    33          BlockedEval: '',
    34          FailedTGAllocs: null,
    35          ClassEligibility: null,
    36          EscapedComputedClass: false,
    37          AnnotatePlan: false,
    38          SnapshotIndex: 53,
    39          QueuedAllocations: {
    40            cache: 0,
    41          },
    42          CreateIndex: 53,
    43          ModifyIndex: 55,
    44          Related: [],
    45        };
    46      });
    47      await store.findRecord('evaluation', 'tomster', {
    48        adapterOptions: { related: true },
    49      });
    50  
    51      server.get('/evaluation/:id', function (_, fakeRes) {
    52        assert.notOk(
    53          fakeRes.queryParams.related,
    54          'it should not append the related query parameter when making the API request for related evaluations'
    55        );
    56        return {
    57          ID: 'tomster',
    58          Priority: 50,
    59          Type: 'service',
    60          TriggeredBy: 'job-register',
    61          JobID: 'example',
    62          JobModifyIndex: 52,
    63          NodeID: 'yes',
    64          NodeModifyIndex: 0,
    65          Status: 'complete',
    66          StatusDescription: '',
    67          Wait: 0,
    68          NextEval: '',
    69          PreviousEval: '',
    70          BlockedEval: '',
    71          FailedTGAllocs: null,
    72          ClassEligibility: null,
    73          EscapedComputedClass: false,
    74          AnnotatePlan: false,
    75          SnapshotIndex: 53,
    76          QueuedAllocations: {
    77            cache: 0,
    78          },
    79          CreateIndex: 53,
    80          ModifyIndex: 55,
    81          Related: [],
    82        };
    83      });
    84      await store.findRecord('evaluation', 'tomster');
    85    });
    86  
    87    test('it should store related evaluations stubs as a hasMany in the store', async function (assert) {
    88      const store = this.owner.lookup('service:store');
    89  
    90      server.get('/evaluation/:id', function () {
    91        return {
    92          ID: 'tomster',
    93          Priority: 50,
    94          Type: 'service',
    95          TriggeredBy: 'job-register',
    96          JobID: 'example',
    97          JobModifyIndex: 52,
    98          NodeID: 'yes',
    99          NodeModifyIndex: 0,
   100          Status: 'complete',
   101          StatusDescription: '',
   102          Wait: 0,
   103          NextEval: '',
   104          PreviousEval: '',
   105          BlockedEval: '',
   106          FailedTGAllocs: null,
   107          ClassEligibility: null,
   108          EscapedComputedClass: false,
   109          AnnotatePlan: false,
   110          SnapshotIndex: 53,
   111          QueuedAllocations: {
   112            cache: 0,
   113          },
   114          CreateIndex: 53,
   115          ModifyIndex: 55,
   116          RelatedEvals: [
   117            { ID: 'a', StatusDescription: 'a' },
   118            { ID: 'b', StatusDescription: 'b' },
   119          ],
   120        };
   121      });
   122  
   123      const result = await store.findRecord('evaluation', 'tomster', {
   124        adapterOptions: { related: true },
   125      });
   126  
   127      assert.equal(result.relatedEvals.length, 2);
   128  
   129      const mappedResult = result.relatedEvals.map((es) => es.id);
   130  
   131      assert.deepEqual(
   132        mappedResult,
   133        ['a', 'b'],
   134        'related evals data is accessible'
   135      );
   136    });
   137  });