summaryrefslogtreecommitdiff
path: root/packages/backend/test/unit/SystemWebhookService.ts
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2025-03-02 18:57:27 +0000
committerdakkar <dakkar@thenautilus.net>2025-03-02 18:57:27 +0000
commit0b5e197afb5f9c2519c22324706c3b27d5d3eea3 (patch)
treec73d3940938e4fd8cc515377f9334c4a48679c7b /packages/backend/test/unit/SystemWebhookService.ts
parentmerge: pin corepack version (!885) (diff)
parentmerge: Add/fix moderation logs for many endpoints (resolves #911 and #969) (!... (diff)
downloadsharkey-0b5e197afb5f9c2519c22324706c3b27d5d3eea3.tar.gz
sharkey-0b5e197afb5f9c2519c22324706c3b27d5d3eea3.tar.bz2
sharkey-0b5e197afb5f9c2519c22324706c3b27d5d3eea3.zip
Merge branch 'develop' into release/2025.2.2
Diffstat (limited to 'packages/backend/test/unit/SystemWebhookService.ts')
-rw-r--r--packages/backend/test/unit/SystemWebhookService.ts49
1 files changed, 44 insertions, 5 deletions
diff --git a/packages/backend/test/unit/SystemWebhookService.ts b/packages/backend/test/unit/SystemWebhookService.ts
index 5401dd74d8..fee4acb305 100644
--- a/packages/backend/test/unit/SystemWebhookService.ts
+++ b/packages/backend/test/unit/SystemWebhookService.ts
@@ -314,9 +314,10 @@ describe('SystemWebhookService', () => {
isActive: true,
on: ['abuseReport'],
});
- await service.enqueueSystemWebhook(webhook.id, 'abuseReport', { foo: 'bar' } as any);
+ await service.enqueueSystemWebhook('abuseReport', { foo: 'bar' } as any);
- expect(queueService.systemWebhookDeliver).toHaveBeenCalled();
+ expect(queueService.systemWebhookDeliver).toHaveBeenCalledTimes(1);
+ expect(queueService.systemWebhookDeliver.mock.calls[0][0] as MiSystemWebhook).toEqual(webhook);
});
test('非アクティブなWebhookはキューに追加されない', async () => {
@@ -324,7 +325,7 @@ describe('SystemWebhookService', () => {
isActive: false,
on: ['abuseReport'],
});
- await service.enqueueSystemWebhook(webhook.id, 'abuseReport', { foo: 'bar' } as any);
+ await service.enqueueSystemWebhook('abuseReport', { foo: 'bar' } as any);
expect(queueService.systemWebhookDeliver).not.toHaveBeenCalled();
});
@@ -338,11 +339,49 @@ describe('SystemWebhookService', () => {
isActive: true,
on: ['abuseReportResolved'],
});
- await service.enqueueSystemWebhook(webhook1.id, 'abuseReport', { foo: 'bar' } as any);
- await service.enqueueSystemWebhook(webhook2.id, 'abuseReport', { foo: 'bar' } as any);
+ await service.enqueueSystemWebhook('abuseReport', { foo: 'bar' } as any);
expect(queueService.systemWebhookDeliver).not.toHaveBeenCalled();
});
+
+ test('混在した時、有効かつ許可されたイベント種別のみ', async () => {
+ const webhook1 = await createWebhook({
+ isActive: true,
+ on: ['abuseReport'],
+ });
+ const webhook2 = await createWebhook({
+ isActive: true,
+ on: ['abuseReportResolved'],
+ });
+ const webhook3 = await createWebhook({
+ isActive: false,
+ on: ['abuseReport'],
+ });
+ const webhook4 = await createWebhook({
+ isActive: false,
+ on: ['abuseReportResolved'],
+ });
+ await service.enqueueSystemWebhook('abuseReport', { foo: 'bar' } as any);
+
+ expect(queueService.systemWebhookDeliver).toHaveBeenCalledTimes(1);
+ expect(queueService.systemWebhookDeliver.mock.calls[0][0] as MiSystemWebhook).toEqual(webhook1);
+ });
+
+ test('除外指定した場合は送信されない', async () => {
+ const webhook1 = await createWebhook({
+ isActive: true,
+ on: ['abuseReport'],
+ });
+ const webhook2 = await createWebhook({
+ isActive: true,
+ on: ['abuseReport'],
+ });
+
+ await service.enqueueSystemWebhook('abuseReport', { foo: 'bar' } as any, { excludes: [webhook2.id] });
+
+ expect(queueService.systemWebhookDeliver).toHaveBeenCalledTimes(1);
+ expect(queueService.systemWebhookDeliver.mock.calls[0][0] as MiSystemWebhook).toEqual(webhook1);
+ });
});
describe('fetchActiveSystemWebhooks', () => {