2020-11-16 12:08:39 +01:00
|
|
|
import {popEmail} from "./_mail_server";
|
|
|
|
import supertest from "supertest";
|
|
|
|
|
|
|
|
export async function followMagicLinkFromMail(
|
|
|
|
agent: supertest.SuperTest<supertest.Test>,
|
|
|
|
cookies: string[],
|
2021-01-21 15:58:03 +01:00
|
|
|
expectedRedirectUrl: string = '/',
|
2020-11-16 12:08:39 +01:00
|
|
|
): Promise<void> {
|
|
|
|
const mail: Record<string, unknown> | null = await popEmail();
|
|
|
|
expect(mail).not.toBeNull();
|
|
|
|
|
|
|
|
const query = (mail?.text as string).split('/magic/link?')[1].split('\n')[0];
|
|
|
|
expect(query).toBeDefined();
|
|
|
|
|
|
|
|
await agent.get('/magic/link?' + query)
|
|
|
|
.expect(200);
|
|
|
|
await agent.get('/magic/lobby')
|
|
|
|
.set('Cookie', cookies)
|
|
|
|
.expect(302)
|
2021-01-21 15:58:03 +01:00
|
|
|
.expect('Location', expectedRedirectUrl);
|
2020-11-16 12:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function testLogout(
|
|
|
|
agent: supertest.SuperTest<supertest.Test>,
|
|
|
|
cookies: string[],
|
|
|
|
csrf: string,
|
|
|
|
): Promise<void> {
|
|
|
|
// Authenticated
|
|
|
|
await agent.get('/is-auth').set('Cookie', cookies).expect(200);
|
|
|
|
|
|
|
|
// Logout
|
|
|
|
await agent.post('/auth/logout')
|
|
|
|
.set('Cookie', cookies)
|
|
|
|
.send({csrf: csrf})
|
|
|
|
.expect(302);
|
|
|
|
|
|
|
|
// Not authenticated
|
|
|
|
await agent.get('/is-auth').set('Cookie', cookies).expect(401);
|
|
|
|
}
|