Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredgalanis committed May 6, 2024
1 parent 4b340db commit 3230705
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 20 deletions.
5 changes: 2 additions & 3 deletions mirage/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ export default function (config) {
});

/** User Service */
this.get('/pass-user-service/whoami', (schema, request) => {
const userId = request.queryParams.userToken;
return schema.find('user', userId);
this.get('/user/whoami', (_schema, _request) => {
return { user: { id: '0' } };
});

/** Download service */
Expand Down
24 changes: 7 additions & 17 deletions tests/acceptance/session-test.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
import { module, test } from 'qunit';
import { visit, currentURL } from '@ember/test-helpers';
import { visit } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import { currentSession, authenticateSession, invalidateSession } from 'ember-simple-auth/test-support';
import { currentSession, authenticateSession } from 'ember-simple-auth/test-support';
import sharedScenario from '../../mirage/scenarios/shared';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';

module('Acceptance | session test', function (hooks) {
module('Acceptance | session', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);

test('authenticating with the correct session data shape results in valid session data', async function (assert) {
await authenticateSession({
id: '0',
});
await visit('/app');

assert.equal(currentURL(), '/app');

let sessionData = currentSession().get('data.authenticated');
assert.equal(sessionData.id, '0');
});
sharedScenario(this.server);

test('authenticating with invalid session data shape still results in valid session data', async function (assert) {
await authenticateSession({
user: {
id: '0',
},
});
await visit('/app');

assert.equal(currentURL(), '/app');

let sessionData = currentSession().get('data.authenticated');
assert.equal(sessionData.id, '0');
});
Expand Down
71 changes: 71 additions & 0 deletions tests/unit/authenticators/http-only-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import HttpOnly from 'pass-ui/authenticators/http-only';
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { setupMirage } from 'ember-cli-mirage/test-support';

module('HttpOnlyAuthenticator', function (hooks) {
setupTest(hooks);
setupMirage(hooks);

let authenticator;

hooks.beforeEach(function () {
authenticator = HttpOnly.create();
});

module('#restore', function () {
test('returns a resolving promise', async function (assert) {
server.get('/user/whoami', (_schema, _request) => {
return {
id: '0',
};
});

const response = await authenticator.restore({ id: '0' });
const expectedResponse = { id: '0' };

assert.strictEqual(response.id, expectedResponse.id);
});

test('returns a resolving promise even when whoami response is not normalized', async function (assert) {
server.get('/user/whoami', (_schema, _request) => {
return {
user: { id: '0' },
};
});

const response = await authenticator.restore({ id: '0' });
const expectedResponse = { id: '0' };

assert.strictEqual(response.id, expectedResponse.id);
});
});

module('#authenticate', function () {
test('returns a resolving promise', async function (assert) {
server.get('/user/whoami', (_schema, _request) => {
return {
id: '0',
};
});

const response = await authenticator.authenticate();
const expectedResponse = { id: '0' };

assert.strictEqual(response.id, expectedResponse.id);
});

test('returns a resolving promise even when whoami response is not normalized', async function (assert) {
server.get('/user/whoami', (_schema, _request) => {
return {
user: { id: '0' },
};
});

const response = await authenticator.authenticate();
const expectedResponse = { id: '0' };

assert.strictEqual(response.id, expectedResponse.id);
});
});
});

0 comments on commit 3230705

Please sign in to comment.