Authentication tests: refactor magic link following from mail
This commit is contained in:
parent
0d0724c315
commit
ef51d128f1
@ -34,6 +34,21 @@ useApp(async (addr, port) => {
|
||||
}(addr, port);
|
||||
});
|
||||
|
||||
async function followMagicLinkFromMail(cookies: string[]): 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)
|
||||
.expect('Location', '/');
|
||||
}
|
||||
|
||||
let agent: supertest.SuperTest<supertest.Test>;
|
||||
|
||||
beforeAll(() => {
|
||||
@ -163,18 +178,7 @@ describe('Register with email (magic_link)', () => {
|
||||
.expect(302)
|
||||
.expect('Location', '/magic/lobby?redirect_uri=%2Fcsrf');
|
||||
|
||||
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)
|
||||
.expect('Location', '/');
|
||||
await followMagicLinkFromMail(cookies);
|
||||
|
||||
// Verify saved user
|
||||
const user = await User.select()
|
||||
@ -225,18 +229,7 @@ describe('Register with email (magic_link)', () => {
|
||||
.expect(302)
|
||||
.expect('Location', '/magic/lobby?redirect_uri=%2Fcsrf');
|
||||
|
||||
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)
|
||||
.expect('Location', '/');
|
||||
await followMagicLinkFromMail(cookies);
|
||||
|
||||
// Verify saved user
|
||||
const user = await User.select()
|
||||
@ -278,18 +271,7 @@ describe('Register with email (magic_link)', () => {
|
||||
.expect(302)
|
||||
.expect('Location', '/magic/lobby?redirect_uri=%2Fcsrf');
|
||||
|
||||
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)
|
||||
.expect('Location', '/');
|
||||
await followMagicLinkFromMail(cookies);
|
||||
|
||||
// Verify saved user
|
||||
const user = await User.select()
|
||||
|
Loading…
Reference in New Issue
Block a user