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