github.com/hernad/nomad@v1.6.112/ui/tests/unit/abilities/recommendation-test.js (about)

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  /* eslint-disable ember/avoid-leaking-state-in-ember-objects */
     7  import { module, test } from 'qunit';
     8  import { setupTest } from 'ember-qunit';
     9  import Service from '@ember/service';
    10  import setupAbility from 'nomad-ui/tests/helpers/setup-ability';
    11  
    12  module('Unit | Ability | recommendation', function (hooks) {
    13    setupTest(hooks);
    14    setupAbility('recommendation')(hooks);
    15  
    16    module(
    17      'when the Dynamic Application Sizing feature is present',
    18      function (hooks) {
    19        hooks.beforeEach(function () {
    20          const mockSystem = Service.extend({
    21            features: ['Dynamic Application Sizing'],
    22          });
    23  
    24          this.owner.register('service:system', mockSystem);
    25        });
    26  
    27        test('it permits accepting recommendations when ACLs are disabled', function (assert) {
    28          const mockToken = Service.extend({
    29            aclEnabled: false,
    30          });
    31  
    32          this.owner.register('service:token', mockToken);
    33  
    34          assert.ok(this.ability.canAccept);
    35        });
    36  
    37        test('it permits accepting recommendations for client tokens where any namespace has submit-job capabilities', function (assert) {
    38          this.owner.lookup('service:system').set('activeNamespace', {
    39            name: 'anotherNamespace',
    40          });
    41  
    42          const mockToken = Service.extend({
    43            aclEnabled: true,
    44            selfToken: { type: 'client' },
    45            selfTokenPolicies: [
    46              {
    47                rulesJSON: {
    48                  Namespaces: [
    49                    {
    50                      Name: 'aNamespace',
    51                      Capabilities: [],
    52                    },
    53                    {
    54                      Name: 'bNamespace',
    55                      Capabilities: ['submit-job'],
    56                    },
    57                  ],
    58                },
    59              },
    60            ],
    61          });
    62  
    63          this.owner.register('service:token', mockToken);
    64  
    65          assert.ok(this.ability.canAccept);
    66        });
    67      }
    68    );
    69  
    70    module(
    71      'when the Dynamic Application Sizing feature is not present',
    72      function (hooks) {
    73        hooks.beforeEach(function () {
    74          const mockSystem = Service.extend({
    75            features: [],
    76          });
    77  
    78          this.owner.register('service:system', mockSystem);
    79        });
    80  
    81        test('it does not permit accepting recommendations regardless of ACL status', function (assert) {
    82          const mockToken = Service.extend({
    83            aclEnabled: false,
    84          });
    85  
    86          this.owner.register('service:token', mockToken);
    87  
    88          assert.notOk(this.ability.canAccept);
    89        });
    90      }
    91    );
    92  });