chore: setup auth redirection logic

This commit is contained in:
Randall Morey committed 2020-07-24 18:08:37 -04:00
1 parent 659a494092
commit 6c1375fe16
6 files changed
+73 -2

No files matched your search

@@ -5,7 +5,7 @@ import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import a11yAudit from 'ember-a11y-testing/test-support/audit';
import {
currentSession,
//authenticateSession,
authenticateSession,
//invalidateSession,
} from 'ember-simple-auth/test-support';
@@ -18,6 +18,7 @@ module('Acceptance | authentication', function(hooks) {
let scope;
let authMethod;
let authMethodID;
let authenticateURL;
let authMethodAuthenticateURL;
let projectsURL;
@@ -27,10 +28,18 @@ module('Acceptance | authentication', function(hooks) {
authMethod = this.server.create('auth-method', { scope });
orgScopeID = orgScope.id;
authMethodID = authMethod.id;
authenticateURL = `/scopes/${orgScopeID}/authenticate`;
authMethodAuthenticateURL = `/scopes/${orgScopeID}/authenticate/${authMethodID}`;
projectsURL = `/scopes/${orgScopeID}/projects`;
});
test('visiting auth methods authenticate route redirects to first auth method', async function(assert) {
assert.expect(1);
await visit(authenticateURL);
await a11yAudit();
assert.equal(currentURL(), authMethodAuthenticateURL);
});
test('visiting auth method authenticate route', async function(assert) {
assert.expect(1);
await visit(authMethodAuthenticateURL);
@@ -38,6 +47,15 @@ module('Acceptance | authentication', function(hooks) {
assert.equal(currentURL(), authMethodAuthenticateURL);
});
test('visiting any authenticate route while already authenticated redirects to projects', async function(assert) {
assert.expect(2);
authenticateSession();
await visit(authenticateURL);
assert.equal(currentURL(), projectsURL);
await visit(authMethodAuthenticateURL);
assert.equal(currentURL(), projectsURL);
});
test('failed authentication shows a notification message', async function(assert) {
assert.expect(3);
await visit(authMethodAuthenticateURL);
@@ -0,0 +1,11 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Route | scopes/scope/authenticate/index', function(hooks) {
setupTest(hooks);
test('it exists', function(assert) {
let route = this.owner.lookup('route:scopes/scope/authenticate/index');
assert.ok(route);
});
});