From d2e22f90507a1920c15d0b997009f52067a2a828 Mon Sep 17 00:00:00 2001 From: おさむのひと <46447427+samunohito@users.noreply.github.com> Date: Tue, 14 Jan 2025 20:14:02 +0900 Subject: refactor: SystemWebhook/UserWebhookの配信処理呼び出し部分の改善 (#15035) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * UserWebhook側の対処 * SystemWebhook側の対処 * fix test --- .../test/unit/AbuseReportNotificationService.ts | 50 +++++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) (limited to 'packages/backend/test/unit/AbuseReportNotificationService.ts') diff --git a/packages/backend/test/unit/AbuseReportNotificationService.ts b/packages/backend/test/unit/AbuseReportNotificationService.ts index 235af29f0d..1326003c5e 100644 --- a/packages/backend/test/unit/AbuseReportNotificationService.ts +++ b/packages/backend/test/unit/AbuseReportNotificationService.ts @@ -3,13 +3,14 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -import { jest } from '@jest/globals'; +import { describe, jest } from '@jest/globals'; import { Test, TestingModule } from '@nestjs/testing'; import { randomString } from '../utils.js'; import { AbuseReportNotificationService } from '@/core/AbuseReportNotificationService.js'; import { AbuseReportNotificationRecipientRepository, MiAbuseReportNotificationRecipient, + MiAbuseUserReport, MiSystemWebhook, MiUser, SystemWebhooksRepository, @@ -112,7 +113,10 @@ describe('AbuseReportNotificationService', () => { provide: SystemWebhookService, useFactory: () => ({ enqueueSystemWebhook: jest.fn() }), }, { - provide: UserEntityService, useFactory: () => ({ pack: (v: any) => v }), + provide: UserEntityService, useFactory: () => ({ + pack: (v: any) => Promise.resolve(v), + packMany: (v: any) => Promise.resolve(v), + }), }, { provide: EmailService, useFactory: () => ({ sendEmail: jest.fn() }), @@ -344,4 +348,46 @@ describe('AbuseReportNotificationService', () => { expect(recipients).toEqual([recipient3]); }); }); + + describe('notifySystemWebhook', () => { + test('非アクティブな通報通知はWebhook送信から除外される', async () => { + const recipient1 = await createRecipient({ + method: 'webhook', + systemWebhookId: systemWebhook1.id, + isActive: true, + }); + const recipient2 = await createRecipient({ + method: 'webhook', + systemWebhookId: systemWebhook2.id, + isActive: false, + }); + + const reports: MiAbuseUserReport[] = [ + { + id: idService.gen(), + targetUserId: alice.id, + targetUser: alice, + reporterId: bob.id, + reporter: bob, + assigneeId: null, + assignee: null, + resolved: false, + forwarded: false, + comment: 'test', + moderationNote: '', + resolvedAs: null, + targetUserHost: null, + reporterHost: null, + }, + ]; + + await service.notifySystemWebhook(reports, 'abuseReport'); + + // 実際に除外されるかはSystemWebhookService側で確認する. + // ここでは非アクティブな通報通知を除外設定できているかを確認する + expect(webhookService.enqueueSystemWebhook).toHaveBeenCalledTimes(1); + expect(webhookService.enqueueSystemWebhook.mock.calls[0][0]).toBe('abuseReport'); + expect(webhookService.enqueueSystemWebhook.mock.calls[0][2]).toEqual({ excludes: [systemWebhook2.id] }); + }); + }); }); -- cgit v1.2.3-freya