40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
import { module, test } from 'qunit';
|
|
import { selectTransport } from 'dashtab/auth/transport';
|
|
|
|
module('Unit | Auth | transport', function () {
|
|
test('selects the web transport without an identity API', function (assert) {
|
|
const transport = selectTransport(null);
|
|
|
|
assert.strictEqual(transport.kind, 'web');
|
|
assert.strictEqual(typeof transport.redirect, 'function');
|
|
});
|
|
|
|
test('selects the extension transport and launches the web auth flow', async function (assert) {
|
|
const calls = [];
|
|
const identity = {
|
|
getRedirectURL: (path) => `https://abc.chromiumapp.org/${path}`,
|
|
launchWebAuthFlow: async (details) => {
|
|
calls.push(details);
|
|
return 'https://abc.chromiumapp.org/discourse?payload=x';
|
|
},
|
|
};
|
|
|
|
const transport = selectTransport(identity);
|
|
|
|
assert.strictEqual(transport.kind, 'extension');
|
|
assert.strictEqual(
|
|
transport.redirectUri('discourse'),
|
|
'https://abc.chromiumapp.org/discourse'
|
|
);
|
|
|
|
const result = await transport.launch('https://forum.example.com/new');
|
|
assert.strictEqual(
|
|
result,
|
|
'https://abc.chromiumapp.org/discourse?payload=x'
|
|
);
|
|
assert.deepEqual(calls, [
|
|
{ url: 'https://forum.example.com/new', interactive: true },
|
|
]);
|
|
});
|
|
});
|