github.com/hernad/nomad@v1.6.112/ui/tests/integration/data-modeling/related-evaluations-test.js (about)

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