Files
hashiccandLisbet Alvarez 3a847605ed Reapply ember-can upgrade (#3111)
* chore: 🤖 reapply previous ember-can upgrade from #3093

* chore: 🤖 add missing ember-inflector dependency

* chore: 🤖 move @ember/string to be a dependency in desktop

* chore: 🤖 re-run pnpm install to resolve lockfile dupe key error

* chore: 🤖 remove unused abilities service injections

Co-Authored-By: Lisbet Alvarez <107949262+lisbet-alvarez@users.noreply.github.com>

---------

Co-authored-by: Lisbet Alvarez <107949262+lisbet-alvarez@users.noreply.github.com>
2026-02-24 13:48:34 -05:00

100 lines
3.0 KiB
JavaScript

/**
* Copyright IBM Corp. 2021, 2026
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Abilities | Target', function (hooks) {
setupTest(hooks);
let abilitiesService;
hooks.beforeEach(function () {
abilitiesService = this.owner.lookup('service:abilities');
});
test('it reflects when a given target may connect based on authorized_actions', function (assert) {
const model = {
authorized_actions: ['authorize-session'],
};
assert.true(abilitiesService.can('connect target', model));
model.authorized_actions = [];
assert.false(abilitiesService.can('connect target', model));
});
test('it reflects when a given target may add host sources', function (assert) {
const model = {
authorized_actions: ['add-host-sources'],
};
assert.true(abilitiesService.can('addHostSources target', model));
model.authorized_actions = [];
assert.false(abilitiesService.can('addHostSources target', model));
});
test('it reflects when a given target may remove host sources', function (assert) {
const model = {
authorized_actions: ['remove-host-sources'],
};
assert.true(abilitiesService.can('removeHostSources target', model));
model.authorized_actions = [];
assert.false(abilitiesService.can('removeHostSources target', model));
});
test('it reflects when a given target may add brokered credential sources', function (assert) {
const model = {
authorized_actions: ['add-credential-sources'],
};
assert.true(
abilitiesService.can('addBrokeredCredentialSources target', model),
);
model.authorized_actions = [];
assert.false(
abilitiesService.can('addBrokeredCredentialSources target', model),
);
});
test('it reflects when a given target may remove credential sources', function (assert) {
const model = {
authorized_actions: ['remove-credential-sources'],
};
assert.true(abilitiesService.can('removeCredentialSources target', model));
model.authorized_actions = [];
assert.false(abilitiesService.can('removeCredentialSources target', model));
});
test('it reflects when a given ssh target may add injected application credential sources', function (assert) {
const model = {
authorized_actions: ['add-credential-sources'],
isSSH: true,
};
const modelWithoutAuthorizedActions = {
authorized_actions: [],
isSSH: true,
};
const modelWithoutSSHType = {
authorized_actions: ['add-credential-sources'],
};
assert.true(
abilitiesService.can(
'addInjectedApplicationCredentialSources target',
model,
),
);
assert.false(
abilitiesService.can(
'addInjectedApplicationCredentialSources target',
modelWithoutAuthorizedActions,
),
);
assert.false(
abilitiesService.can(
'addInjectedApplicationCredentialSources target',
modelWithoutSSHType,
),
);
});
});