Files
threshold-ui/addons/auth/tests/unit/authenticators/oidc-test.js
T
Randall MoreyandSusmitha Girumala a2e27b09c3 refactor: 💡 add standalone server mocks to auth tests (#1283)
* refactor: 💡 replace ember notify with flash in notify decorator

* refactor: 💡 remove embery-notify and replace last instance

* chore: 🤖 upgrade ember dependencies in anticipation of ember 4

* refactor: 💡 add standalone server mocks to auth tests

Co-authored-by: Susmitha Girumala <susmitha@hashicorp.com>
2022-09-01 15:40:00 -04:00

43 lines
1.3 KiB
JavaScript

import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import Pretender from 'pretender';
module('Unit | Authenticator | OIDC', function (hooks) {
setupTest(hooks);
let server;
hooks.beforeEach(() => {
server = new Pretender();
});
hooks.afterEach(() => {
server.shutdown();
});
test('`startAuthentication` initiates the authentication flow and returns the response', async function (assert) {
assert.expect(2);
const authenticator = this.owner.lookup('authenticator:oidc');
server.post(authenticator.buildAuthEndpointURL(), () => [
200,
{},
JSON.stringify({ 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');
server.post(authenticator.buildAuthEndpointURL(), () => [400]);
// Because assert.throws doesn't work with async errors/promise rejections
try {
await authenticator.startAuthentication();
} catch (e) {
assert.ok(true);
}
});
});