Files
threshold-ui/addons/auth/tests/unit/authenticators/oidc-test.js
T

36 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-03-19 17:03:03 -04:00
import { module, test } from 'qunit';
2021-01-15 11:10:33 -05:00
import { setupTest } from 'ember-qunit';
2021-03-19 17:03:03 -04:00
import { Response } from 'miragejs';
2021-01-15 11:10:33 -05:00
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
module('Unit | Authenticator | OIDC', function (hooks) {
setupTest(hooks);
setupMirage(hooks);
2021-03-19 17:03:03 -04:00
test('`startAuthentication` initiates the authentication flow and returns the response', async function (assert) {
assert.expect(2);
const authenticator = this.owner.lookup('authenticator:oidc');
this.server.post(
authenticator.buildAuthEndpointURL(),
2021-03-19 17:03:03 -04:00
() => new Response(200, {}, { foo: 'bar' })
);
const response = await authenticator.startAuthentication();
assert.ok(true, 'authentication succeeded');
assert.deepEqual(response, { foo: 'bar' });
});
test('`startAuthentication` rejects/errors if API returns an error response', async function (assert) {
assert.expect(1);
const authenticator = this.owner.lookup('authenticator:oidc');
this.server.post(
authenticator.buildAuthEndpointURL(),
2021-03-19 17:03:03 -04:00
() => new Response(400)
);
// Because assert.throws doesn't work with async errors/promise rejections
try {
await authenticator.startAuthentication();
} catch (e) {
assert.ok(true);
}
});
2021-01-15 11:10:33 -05:00
});