Skip to content

Commit

Permalink
feat(typescript): migrate test-support
Browse files Browse the repository at this point in the history
  • Loading branch information
BobrImperator committed Dec 27, 2024
1 parent 2bd1419 commit 2114200
Showing 1 changed file with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Test from '../authenticators/test';
const SESSION_SERVICE_KEY = 'service:session';
const TEST_CONTAINER_KEY = 'authenticator:test';

function ensureAuthenticator(owner) {
function ensureAuthenticator(owner: any) {
const authenticator = owner.lookup(TEST_CONTAINER_KEY);
if (!authenticator) {
owner.register(TEST_CONTAINER_KEY, Test);
Expand All @@ -20,13 +20,13 @@ function ensureAuthenticator(owner) {
* @return {Promise}
* @public
*/
export function authenticateSession(sessionData) {
const { owner } = getContext();
export async function authenticateSession(sessionData: Record<string, string>) {
const { owner } = getContext() as { owner: any };
const session = owner.lookup(SESSION_SERVICE_KEY);
ensureAuthenticator(owner);
return session.authenticate(TEST_CONTAINER_KEY, sessionData).then(() => {
return settled();
});

await session.authenticate(TEST_CONTAINER_KEY, sessionData);
await settled();
}

/**
Expand All @@ -36,7 +36,7 @@ export function authenticateSession(sessionData) {
* @public
*/
export function currentSession() {
const { owner } = getContext();
const { owner } = getContext() as { owner: any };
return owner.lookup(SESSION_SERVICE_KEY);
}

Expand All @@ -46,15 +46,14 @@ export function currentSession() {
* @return {Promise}
* @public
*/
export function invalidateSession() {
const { owner } = getContext();
export async function invalidateSession() {
const { owner } = getContext() as { owner: any };
const session = owner.lookup(SESSION_SERVICE_KEY);
const isAuthenticated = get(session, 'isAuthenticated');
return Promise.resolve()
.then(() => {
if (isAuthenticated) {
return session.invalidate();
}
})
.then(() => settled());

if (isAuthenticated) {
return session.invalidate();
}

await settled();
}

0 comments on commit 2114200

Please sign in to comment.