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

169 lines
5.2 KiB
JavaScript

/**
* Copyright IBM Corp. 2021, 2026
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import {
STATUS_SESSION_ACTIVE,
STATUS_SESSION_PENDING,
STATUS_SESSION_CANCELING,
STATUS_SESSION_TERMINATED,
} from 'api/models/session';
module('Unit | Ability | session', function (hooks) {
setupTest(hooks);
let abilitiesService;
let store;
hooks.beforeEach(function () {
abilitiesService = this.owner.lookup('service:abilities');
store = this.owner.lookup('service:store');
});
test('it exists', function (assert) {
const ability = this.owner.lookup('ability:session');
assert.ok(ability);
});
test('can read a session that is active', function (assert) {
const session = store.createRecord('session', {
authorized_actions: ['read'],
status: STATUS_SESSION_ACTIVE,
});
assert.true(abilitiesService.can('read session', session));
});
test('can read a session that is pending', function (assert) {
const session = store.createRecord('session', {
authorized_actions: ['read'],
status: STATUS_SESSION_PENDING,
});
assert.true(abilitiesService.can('read session', session));
});
test('cannot read a session that is not authorized', function (assert) {
const activeSession = store.createRecord('session', {
authorized_actions: [],
status: STATUS_SESSION_ACTIVE,
});
const pendingSession = store.createRecord('session', {
authorized_actions: [],
status: STATUS_SESSION_PENDING,
});
const cancelingSession = store.createRecord('session', {
authorized_actions: [],
status: STATUS_SESSION_CANCELING,
});
const terminatedSession = store.createRecord('session', {
authorized_actions: [],
status: STATUS_SESSION_TERMINATED,
});
assert.false(abilitiesService.can('read session', activeSession));
assert.false(abilitiesService.can('read session', pendingSession));
assert.false(abilitiesService.can('read session', cancelingSession));
assert.false(abilitiesService.can('read session', terminatedSession));
});
test('cannot read a session that is canceling', function (assert) {
const session = store.createRecord('session', {
authorized_actions: ['read'],
status: STATUS_SESSION_CANCELING,
});
assert.false(abilitiesService.can('read session', session));
});
test('cannot read a session that is terminated', function (assert) {
const session = store.createRecord('session', {
authorized_actions: ['read'],
status: STATUS_SESSION_TERMINATED,
});
assert.false(abilitiesService.can('read session', session));
});
test('can read a session that has read:self', function (assert) {
const session = store.createRecord('session', {
authorized_actions: ['read:self'],
status: STATUS_SESSION_ACTIVE,
});
assert.true(abilitiesService.can('read session', session));
});
test('can cancel a session that is active', function (assert) {
const session = store.createRecord('session', {
authorized_actions: ['cancel'],
status: STATUS_SESSION_ACTIVE,
});
assert.true(abilitiesService.can('cancel session', session));
});
test('can cancel a session that has cancel:self', function (assert) {
const session = store.createRecord('session', {
authorized_actions: ['cancel:self'],
status: STATUS_SESSION_ACTIVE,
});
assert.true(abilitiesService.can('cancel session', session));
});
test('can cancel a session that is pending', function (assert) {
const session = store.createRecord('session', {
authorized_actions: ['cancel'],
status: STATUS_SESSION_PENDING,
});
assert.true(abilitiesService.can('cancel session', session));
});
test('cannot cancel a session that is canceling', function (assert) {
const session = store.createRecord('session', {
authorized_actions: ['cancel'],
status: STATUS_SESSION_CANCELING,
});
assert.false(abilitiesService.can('cancel session', session));
});
test('cannot cancel a session that is terminated', function (assert) {
const session = store.createRecord('session', {
authorized_actions: ['cancel'],
status: STATUS_SESSION_TERMINATED,
});
assert.false(abilitiesService.can('cancel session', session));
});
test('cannot cancel a session that is not authorized', function (assert) {
const activeSession = store.createRecord('session', {
authorized_actions: [],
status: STATUS_SESSION_ACTIVE,
});
const pendingSession = store.createRecord('session', {
authorized_actions: [],
status: STATUS_SESSION_PENDING,
});
const cancelingSession = store.createRecord('session', {
authorized_actions: [],
status: STATUS_SESSION_CANCELING,
});
const terminatedSession = store.createRecord('session', {
authorized_actions: [],
status: STATUS_SESSION_TERMINATED,
});
assert.false(abilitiesService.can('cancel session', activeSession));
assert.false(abilitiesService.can('cancel session', pendingSession));
assert.false(abilitiesService.can('cancel session', cancelingSession));
assert.false(abilitiesService.can('cancel session', terminatedSession));
});
});