Files

168 lines
5.2 KiB
JavaScript
Raw Permalink Normal View History

/**
2026-01-28 17:09:06 -08:00
* 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);
2026-02-24 13:48:34 -05:00
let abilitiesService;
let store;
hooks.beforeEach(function () {
2026-02-24 13:48:34 -05:00
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,
});
2026-02-24 13:48:34 -05:00
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,
});
2026-02-24 13:48:34 -05:00
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,
});
2026-02-24 13:48:34 -05:00
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,
});
2026-02-24 13:48:34 -05:00
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,
});
2026-02-24 13:48:34 -05:00
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,
});
2026-02-24 13:48:34 -05:00
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,
});
2026-02-24 13:48:34 -05:00
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,
});
2026-02-24 13:48:34 -05:00
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,
});
2026-02-24 13:48:34 -05:00
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,
});
2026-02-24 13:48:34 -05:00
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,
});
2026-02-24 13:48:34 -05:00
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,
});
2026-02-24 13:48:34 -05:00
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));
});
});