Files
threshold-ui/addons/api/tests/unit/models/session-test.js
T
Cameron Perera 6e75439652 Icu 12587 add filtering pagination support for sessions (#2194)
* feat: 🎸 add pagination and filtering to sessions page

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12587

* refactor: 💡 fix handling of null values in indexed-db-query

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12587

* refactor: 💡 add method signatures where missing

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12587

* refactor: 💡 address PR feedback

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12587

* fix: 🐛 add override for table header color when sortable

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12587

* refactor: 💡 remove poller and add manual refresh action

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12587

* refactor: 💡 remove force_refresh from sessions route queries

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12587

* refactor: 💡 add user getter to session model

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12587

* refactor: 💡 remove logicalOperator value from queries

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12587

* refactor: 💡 move action to controller from router

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12587

* refactor: 💡 remove cleanValues from indexed-db-query

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12587

* refactor: 💡 remove potential null values for user/target ids

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12587

* refactor: 💡 add async/await back to cancelSession

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12587

* refactor: 💡 update sessions route

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12587

* refactor: 💡 use translation string for Sessions

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12587

* test: 💍 fix controller test

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12587

* refactor: 💡 add scope_id to filters for query

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12587

* refactor: 💡 remove scope_id and recursive in sessions query

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12587

* refactor: 💡 how user query to use global and org scope

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12587
2024-04-12 14:55:33 -04:00

160 lines
4.3 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Model | session', function (hooks) {
setupTest(hooks);
test('it exists', function (assert) {
let store = this.owner.lookup('service:store');
let model = store.createRecord('session', {});
assert.ok(model);
assert.notOk(model.isAvailable);
});
test('it allows cancellation of an active session', function (assert) {
let store = this.owner.lookup('service:store');
let model = store.createRecord('session', {
status: 'active',
});
assert.ok(model.isAvailable);
});
test('it allows cancellation of a pending session', function (assert) {
let store = this.owner.lookup('service:store');
let model = store.createRecord('session', {
status: 'pending',
});
assert.ok(model.isAvailable);
});
test('it computes isActive', function (assert) {
let store = this.owner.lookup('service:store');
let model = store.createRecord('session', {
status: 'pending',
});
assert.notOk(model.isActive);
model.status = 'active';
assert.ok(model.isActive);
});
test('it computes isPending', function (assert) {
let store = this.owner.lookup('service:store');
let model = store.createRecord('session', {
status: 'active',
});
assert.notOk(model.isPending);
model.status = 'pending';
assert.ok(model.isPending);
});
test('it computes a proxy attribute', function (assert) {
let store = this.owner.lookup('service:store');
let model = store.createRecord('session');
assert.strictEqual(model.proxy, null);
model.setProperties({
proxy_address: 'localhost',
proxy_port: '12345',
});
assert.strictEqual(model.proxy, 'localhost:12345');
});
test('it has isUnknownStatus property and returns the expected values', async function (assert) {
const store = this.owner.lookup('service:store');
const modelA = store.createRecord('session', { status: 'active' });
const modelB = store.createRecord('session', {
status: 'any string',
});
assert.false(modelA.isUnknownStatus);
assert.true(modelB.isUnknownStatus);
});
test('it has target property and returns the null with no target_id set', function (assert) {
const store = this.owner.lookup('service:store');
store.push({
data: {
id: 's_123',
type: 'session',
attributes: { target_id: null },
},
});
const session = store.peekRecord('session', 's_123');
assert.strictEqual(session.target, null);
});
test('it has target property and returns the correct target', function (assert) {
const store = this.owner.lookup('service:store');
const targetId = 'ttcp_123';
store.push({
data: {
id: targetId,
type: 'target',
attributes: {
name: 'admin',
scope: {
scope_id: 'o_1',
type: 'scope',
},
},
},
});
store.push({
data: {
id: 's_123',
type: 'session',
attributes: { target_id: targetId },
},
});
const session = store.peekRecord('session', 's_123');
assert.strictEqual(session.target.id, targetId);
});
test('it has user property and returns the null with no user_id set', function (assert) {
const store = this.owner.lookup('service:store');
store.push({
data: {
id: 's_123',
type: 'session',
attributes: { user_id: null },
},
});
const session = store.peekRecord('session', 's_123');
assert.strictEqual(session.user, null);
});
test('it has user property and returns the correct user', function (assert) {
const store = this.owner.lookup('service:store');
const userId = 'u_123';
store.push({
data: {
id: userId,
type: 'user',
attributes: {
name: 'admin',
scope: {
scope_id: 'o_1',
type: 'scope',
},
},
},
});
store.push({
data: {
id: 's_123',
type: 'session',
attributes: { user_id: userId },
},
});
const session = store.peekRecord('session', 's_123');
assert.strictEqual(session.user.id, userId);
});
});