Files
threshold-ui/addons/auth/tests/unit/authenticators/oidc-test.js
T
hashicorp-copywrite[bot]andCameron Perera 3d610427d0 [COMPLIANCE] Add Copyright and License Headers (#1617)
* [COMPLIANCE] Add Copyright and License Headers

* chore: 🤖 update Copyright headers to satisfy our lint rules

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>
2023-03-01 09:39:41 -06:00

48 lines
1.3 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
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);
}
});
});