fix(backend): Send Abuse Reports To Set Maintainer E-Mail
This commit is contained in:
parent
c35da729fc
commit
789deeabac
2 changed files with 93 additions and 9 deletions
|
|
@ -11,6 +11,7 @@ import {
|
|||
AbuseReportNotificationRecipientRepository,
|
||||
MiAbuseReportNotificationRecipient,
|
||||
MiAbuseUserReport,
|
||||
MiMeta,
|
||||
MiSystemWebhook,
|
||||
MiUser,
|
||||
SystemWebhooksRepository,
|
||||
|
|
@ -56,6 +57,16 @@ describe('AbuseReportNotificationService', () => {
|
|||
|
||||
// --------------------------------------------------------------------------------------
|
||||
|
||||
const metaInitial = {} as MiMeta;
|
||||
const meta = { ...metaInitial };
|
||||
|
||||
function updateMeta(newMeta: Partial<MiMeta>): void {
|
||||
for (const key in meta) {
|
||||
delete (meta as any)[key];
|
||||
}
|
||||
Object.assign(meta, newMeta);
|
||||
}
|
||||
|
||||
async function createUser(data: Partial<MiUser> = {}) {
|
||||
const user = await usersRepository
|
||||
.insert({
|
||||
|
|
@ -66,6 +77,8 @@ describe('AbuseReportNotificationService', () => {
|
|||
|
||||
await userProfilesRepository.insert({
|
||||
userId: user.id,
|
||||
email: user.username + '@example.com',
|
||||
emailVerified: true,
|
||||
});
|
||||
|
||||
return user;
|
||||
|
|
@ -130,6 +143,9 @@ describe('AbuseReportNotificationService', () => {
|
|||
{
|
||||
provide: GlobalEventService, useFactory: () => ({ publishAdminStream: jest.fn() }),
|
||||
},
|
||||
{
|
||||
provide: DI.meta, useFactory: () => meta,
|
||||
},
|
||||
],
|
||||
})
|
||||
.compile();
|
||||
|
|
@ -156,6 +172,8 @@ describe('AbuseReportNotificationService', () => {
|
|||
systemWebhook2 = await createWebhook();
|
||||
|
||||
roleService.getModeratorIds.mockResolvedValue([root.id, alice.id, bob.id]);
|
||||
|
||||
updateMeta({} as MiMeta);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
|
|
@ -392,4 +410,59 @@ describe('AbuseReportNotificationService', () => {
|
|||
expect(webhookService.enqueueSystemWebhook.mock.calls[0][2]).toEqual({ excludes: [systemWebhook2.id] });
|
||||
});
|
||||
});
|
||||
|
||||
describe('collection of recipient-mails', () => {
|
||||
async function create() {
|
||||
const recipient = await createRecipient({
|
||||
method: 'email',
|
||||
userId: alice.id,
|
||||
});
|
||||
|
||||
return recipient;
|
||||
}
|
||||
|
||||
test('with nothing set', async () => {
|
||||
const mails = await service.getRecipientEMailAddresses();
|
||||
expect(mails).toEqual([]);
|
||||
});
|
||||
|
||||
test('with maintainer mail set', async () => {
|
||||
updateMeta({ maintainerEmail: 'maintainer_mail' });
|
||||
const mails = await service.getRecipientEMailAddresses();
|
||||
expect(mails).toEqual(['maintainer_mail']);
|
||||
});
|
||||
|
||||
test('with smtp mail set', async () => {
|
||||
updateMeta({ email: 'smtp_mail' });
|
||||
const mails = await service.getRecipientEMailAddresses();
|
||||
expect(mails).toEqual(['smtp_mail']);
|
||||
});
|
||||
|
||||
test('with maintainer mail and smtp mail set', async () => {
|
||||
updateMeta({ email: 'smtp_mail', maintainerEmail: 'maintainer_mail' });
|
||||
const mails = await service.getRecipientEMailAddresses();
|
||||
expect(mails).toEqual(['smtp_mail', 'maintainer_mail']);
|
||||
});
|
||||
|
||||
test('with recipients', async () => {
|
||||
await create();
|
||||
|
||||
const mails = await service.getRecipientEMailAddresses();
|
||||
expect(mails).toEqual([
|
||||
'alice@example.com',
|
||||
]);
|
||||
});
|
||||
|
||||
test('with recipients and maintainer mail set and smtp mail set', async () => {
|
||||
await create();
|
||||
updateMeta({ maintainerEmail: 'maintainer_mail', email: 'smtp_mail' });
|
||||
|
||||
const mails = await service.getRecipientEMailAddresses();
|
||||
expect(mails).toEqual([
|
||||
'alice@example.com',
|
||||
'smtp_mail',
|
||||
'maintainer_mail',
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue