parent
49168b5391
commit
93c41ebd7e
@ -809,6 +809,21 @@ describe('Change password', () => {
|
||||
|
||||
|
||||
describe('Manage email addresses', () => {
|
||||
|
||||
async function testMainSecondaryState(main: string, secondary: string) {
|
||||
const user = await User.select('main_email_id').where('name', 'katara').first();
|
||||
|
||||
const mainEmail = await UserEmail.select().where('email', main).first();
|
||||
expect(mainEmail).not.toBeNull();
|
||||
expect(user?.main_email_id).toBe(mainEmail?.id);
|
||||
|
||||
const secondaryEmail = await UserEmail.select().where('email', secondary).first();
|
||||
expect(secondaryEmail).not.toBeNull();
|
||||
expect(user?.main_email_id).not.toBe(secondaryEmail?.id);
|
||||
|
||||
return secondaryEmail;
|
||||
}
|
||||
|
||||
let cookies: string[], csrf: string;
|
||||
test('Prepare user', async () => {
|
||||
const res = await agent.get('/csrf').expect(200);
|
||||
@ -839,6 +854,7 @@ describe('Manage email addresses', () => {
|
||||
}).save();
|
||||
});
|
||||
|
||||
describe('Add', () => {
|
||||
test('Add invalid email addresses', async () => {
|
||||
await agent.post('/account/add-email')
|
||||
.set('Cookie', cookies)
|
||||
@ -864,7 +880,7 @@ describe('Manage email addresses', () => {
|
||||
expect(await UserEmail.select().where('email', 'katara@example.org').count()).toBe(1);
|
||||
});
|
||||
|
||||
test('Add valid email', async () => {
|
||||
test('Add valid email addresses', async () => {
|
||||
const expectedUserId = (await User.select('id').where('name', 'katara').first())?.id;
|
||||
|
||||
for (const email of [
|
||||
@ -888,21 +904,9 @@ describe('Manage email addresses', () => {
|
||||
expect(userEmail?.user_id).toBe(expectedUserId);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
async function testMainSecondaryState(main: string, secondary: string) {
|
||||
const user = await User.select('main_email_id').where('name', 'katara').first();
|
||||
|
||||
const mainEmail = await UserEmail.select().where('email', main).first();
|
||||
expect(mainEmail).not.toBeNull();
|
||||
expect(user?.main_email_id).toBe(mainEmail?.id);
|
||||
|
||||
const secondaryEmail = await UserEmail.select().where('email', secondary).first();
|
||||
expect(secondaryEmail).not.toBeNull();
|
||||
expect(user?.main_email_id).not.toBe(secondaryEmail?.id);
|
||||
|
||||
return secondaryEmail;
|
||||
}
|
||||
|
||||
describe('Set main', () => {
|
||||
test('Set main email address as main email address', async () => {
|
||||
await testMainSecondaryState('katara@example.org', 'katara3@example.org');
|
||||
|
||||
@ -963,7 +967,9 @@ describe('Manage email addresses', () => {
|
||||
|
||||
await testMainSecondaryState('katara3@example.org', 'katara4@example.org');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Remove', () => {
|
||||
test('Remove secondary email address', async () => {
|
||||
expect(await UserEmail.select().where('email', 'katara2@example.org').count()).toBe(1);
|
||||
|
||||
@ -1021,3 +1027,4 @@ describe('Manage email addresses', () => {
|
||||
expect(await UserEmail.select().where('email', 'katara3@example.org').count()).toBe(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user