Add tests for password remove flow

Closes #28
This commit is contained in:
Alice Gaudon 2021-02-21 16:28:13 +01:00
parent 21f161a83a
commit 3ce81e25cf

View File

@ -806,6 +806,69 @@ describe('Change password', () => {
expect(await user?.as(UserPasswordComponent).verifyPassword('a_very_strong_password_but_different')).toBeTruthy();
expect(await user?.as(UserPasswordComponent).verifyPassword('123')).toBeFalsy();
});
test('Remove password', async () => {
let user = await User.select()
.where('name', 'aang')
.first();
expect(user).toBeDefined();
expect(user?.as(UserPasswordComponent).hasPassword()).toBe(true);
await agent.post('/account/remove-password')
.set('Cookie', cookies)
.send({
csrf: csrf,
})
.expect(302)
.expect('Location', '/magic/lobby?redirect_uri=%2Faccount%2F');
await followMagicLinkFromMail(agent, cookies, '/account/');
user = await User.select()
.where('name', 'aang')
.first();
expect(user).toBeDefined();
expect(user?.as(UserPasswordComponent).hasPassword()).toBe(false);
});
test('Can\'t remove password without contact email', async () => {
const res = await agent.get('/csrf').expect(200);
cookies = res.get('Set-Cookie');
csrf = res.text;
await agent.post('/auth/register')
.set('Cookie', cookies)
.send({
csrf: csrf,
auth_method: 'password',
identifier: 'eleanor',
password: 'this_is_a_very_strong_password',
password_confirmation: 'this_is_a_very_strong_password',
terms: 'on',
})
.expect(302)
.expect('Location', '/');
let user = await User.select()
.where('name', 'eleanor')
.first();
expect(user).toBeDefined();
expect(user?.as(UserPasswordComponent).hasPassword()).toBe(true);
await agent.post('/account/remove-password')
.set('Cookie', cookies)
.send({
csrf: csrf,
})
.expect(302)
.expect('Location', '/account/');
user = await User.select()
.where('name', 'eleanor')
.first();
expect(user).toBeDefined();
expect(user?.as(UserPasswordComponent).hasPassword()).toBe(true);
});
});