* empty commit
* Add missing copyright headers
* chore: 🤖 update copywrite config file with correct year
* Add missing copyright headers
* empty commit (gh action merge checks are stuck)
110 lines
3.0 KiB
JavaScript
110 lines
3.0 KiB
JavaScript
/**
|
|
* Copyright IBM Corp. 2021, 2026
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { module, test } from 'qunit';
|
|
import { visit, currentURL } from '@ember/test-helpers';
|
|
import { setupApplicationTest } from 'desktop/tests/helpers';
|
|
import {
|
|
currentSession,
|
|
invalidateSession,
|
|
} from 'ember-simple-auth/test-support';
|
|
import WindowMockIPC from '../helpers/window-mock-ipc';
|
|
|
|
module('Acceptance | projects', function (hooks) {
|
|
setupApplicationTest(hooks);
|
|
|
|
const instances = {
|
|
scopes: {
|
|
global: null,
|
|
org: null,
|
|
project: null,
|
|
},
|
|
authMethods: {
|
|
global: null,
|
|
},
|
|
target: null,
|
|
};
|
|
|
|
const stubs = {
|
|
global: null,
|
|
org: null,
|
|
};
|
|
|
|
const urls = {
|
|
index: '/',
|
|
clusterUrl: '/cluster-url',
|
|
scopes: {
|
|
global: null,
|
|
org: null,
|
|
},
|
|
authenticate: {
|
|
global: null,
|
|
methods: {
|
|
global: null,
|
|
},
|
|
},
|
|
projects: null,
|
|
};
|
|
|
|
const setDefaultClusterUrl = (test) => {
|
|
const windowOrigin = window.location.origin;
|
|
const clusterUrl = test.owner.lookup('service:clusterUrl');
|
|
clusterUrl.rendererClusterUrl = windowOrigin;
|
|
};
|
|
|
|
hooks.beforeEach(async function () {
|
|
instances.scopes.global = this.server.schema.scopes.find('global');
|
|
instances.authMethods.global = this.server.schema.authMethods.first();
|
|
stubs.global = { id: 'global', type: 'global' };
|
|
instances.scopes.org = this.server.create('scope', {
|
|
type: 'org',
|
|
scope: stubs.global,
|
|
});
|
|
stubs.org = { id: instances.scopes.org.id, type: 'org' };
|
|
instances.scopes.project = this.server.create('scope', {
|
|
type: 'project',
|
|
scope: stubs.org,
|
|
});
|
|
stubs.project = { id: instances.scopes.project.id, type: 'project' };
|
|
|
|
instances.hostCatalog = this.server.create(
|
|
'host-catalog',
|
|
{ scope: instances.scopes.project },
|
|
'withChildren',
|
|
);
|
|
instances.target = this.server.create(
|
|
'target',
|
|
{ scope: instances.scopes.project },
|
|
'withAssociations',
|
|
);
|
|
|
|
urls.scopes.global = `/scopes/${instances.scopes.global.id}`;
|
|
urls.scopes.org = `/scopes/${instances.scopes.org.id}`;
|
|
urls.authenticate.global = `${urls.scopes.global}/authenticate`;
|
|
urls.authenticate.methods.global = `${urls.authenticate.global}/${instances.authMethods.global.id}`;
|
|
urls.projects = `${urls.scopes.org}/projects`;
|
|
|
|
// Mock the postMessage interface used by IPC.
|
|
this.owner.register('service:browser/window', WindowMockIPC);
|
|
setDefaultClusterUrl(this);
|
|
});
|
|
|
|
test('visiting index while unauthenticated redirects to global authenticate method', async function (assert) {
|
|
await invalidateSession();
|
|
assert.expect(2);
|
|
await visit(urls.projects);
|
|
|
|
assert.notOk(currentSession().isAuthenticated);
|
|
assert.strictEqual(currentURL(), urls.authenticate.methods.global);
|
|
});
|
|
|
|
test('visiting index', async function (assert) {
|
|
assert.expect(1);
|
|
await visit(urls.projects);
|
|
|
|
assert.strictEqual(currentURL(), urls.projects);
|
|
});
|
|
});
|