2023-03-01 09:39:41 -06:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2020-09-18 10:16:40 -04:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
|
import { setupTest } from 'ember-qunit';
|
|
|
|
|
|
2021-03-04 15:47:38 -05:00
|
|
|
module('Unit | Model | session', function (hooks) {
|
2020-09-18 10:16:40 -04:00
|
|
|
setupTest(hooks);
|
|
|
|
|
|
2021-03-04 15:47:38 -05:00
|
|
|
test('it exists', function (assert) {
|
2020-09-18 10:16:40 -04:00
|
|
|
let store = this.owner.lookup('service:store');
|
|
|
|
|
let model = store.createRecord('session', {});
|
|
|
|
|
assert.ok(model);
|
2023-11-01 11:22:18 -05:00
|
|
|
assert.notOk(model.isAvailable);
|
2020-10-05 16:09:34 -04:00
|
|
|
});
|
|
|
|
|
|
2021-03-04 15:47:38 -05:00
|
|
|
test('it allows cancellation of an active session', function (assert) {
|
2020-10-05 16:09:34 -04:00
|
|
|
let store = this.owner.lookup('service:store');
|
|
|
|
|
let model = store.createRecord('session', {
|
2021-03-04 15:47:38 -05:00
|
|
|
status: 'active',
|
2020-10-05 16:09:34 -04:00
|
|
|
});
|
2023-11-01 11:22:18 -05:00
|
|
|
assert.ok(model.isAvailable);
|
2020-10-05 16:09:34 -04:00
|
|
|
});
|
|
|
|
|
|
2021-03-04 15:47:38 -05:00
|
|
|
test('it allows cancellation of a pending session', function (assert) {
|
2020-10-05 16:09:34 -04:00
|
|
|
let store = this.owner.lookup('service:store');
|
|
|
|
|
let model = store.createRecord('session', {
|
2021-03-04 15:47:38 -05:00
|
|
|
status: 'pending',
|
2020-10-05 16:09:34 -04:00
|
|
|
});
|
2023-11-01 11:22:18 -05:00
|
|
|
assert.ok(model.isAvailable);
|
2020-09-18 10:16:40 -04:00
|
|
|
});
|
2021-02-03 14:29:13 -05:00
|
|
|
|
2021-02-05 16:57:06 -05:00
|
|
|
test('it computes isActive', function (assert) {
|
|
|
|
|
let store = this.owner.lookup('service:store');
|
|
|
|
|
let model = store.createRecord('session', {
|
2021-03-04 15:47:38 -05:00
|
|
|
status: 'pending',
|
2021-02-05 16:57:06 -05:00
|
|
|
});
|
|
|
|
|
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', {
|
2021-03-04 15:47:38 -05:00
|
|
|
status: 'active',
|
2021-02-05 16:57:06 -05:00
|
|
|
});
|
|
|
|
|
assert.notOk(model.isPending);
|
|
|
|
|
model.status = 'pending';
|
|
|
|
|
assert.ok(model.isPending);
|
|
|
|
|
});
|
|
|
|
|
|
2021-02-03 14:29:13 -05:00
|
|
|
test('it computes a proxy attribute', function (assert) {
|
|
|
|
|
let store = this.owner.lookup('service:store');
|
|
|
|
|
let model = store.createRecord('session');
|
2022-07-07 11:18:51 -07:00
|
|
|
assert.strictEqual(model.proxy, null);
|
2021-02-03 14:29:13 -05:00
|
|
|
model.setProperties({
|
|
|
|
|
proxy_address: 'localhost',
|
2021-03-04 15:47:38 -05:00
|
|
|
proxy_port: '12345',
|
2021-02-03 14:29:13 -05:00
|
|
|
});
|
2022-07-07 11:18:51 -07:00
|
|
|
assert.strictEqual(model.proxy, 'localhost:12345');
|
2021-02-03 14:29:13 -05:00
|
|
|
});
|
2022-11-11 14:14:31 -08:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
});
|
2020-09-18 10:16:40 -04:00
|
|
|
});
|