refactor: SystemWebhook/UserWebhookの配信処理呼び出し部分の改善 (#15035)
* UserWebhook側の対処 * SystemWebhook側の対処 * fix test
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
/*
|
||||
* SPDX-FileCopyrightText: syuilo and misskey-project
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
@@ -71,7 +70,7 @@ describe('UserWebhookService', () => {
|
||||
LoggerService,
|
||||
GlobalEventService,
|
||||
{
|
||||
provide: QueueService, useFactory: () => ({ systemWebhookDeliver: jest.fn() }),
|
||||
provide: QueueService, useFactory: () => ({ userWebhookDeliver: jest.fn() }),
|
||||
},
|
||||
],
|
||||
})
|
||||
@@ -242,4 +241,92 @@ describe('UserWebhookService', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('アプリを毎回作り直す必要があるグループ', () => {
|
||||
beforeEach(async () => {
|
||||
await beforeAllImpl();
|
||||
await beforeEachImpl();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await afterEachImpl();
|
||||
await afterAllImpl();
|
||||
});
|
||||
|
||||
describe('enqueueUserWebhook', () => {
|
||||
test('キューに追加成功', async () => {
|
||||
const webhook = await createWebhook({
|
||||
active: true,
|
||||
on: ['note'],
|
||||
});
|
||||
await service.enqueueUserWebhook(webhook.userId, 'note', { foo: 'bar' } as any);
|
||||
|
||||
expect(queueService.userWebhookDeliver).toHaveBeenCalledTimes(1);
|
||||
expect(queueService.userWebhookDeliver.mock.calls[0][0] as MiWebhook).toEqual(webhook);
|
||||
});
|
||||
|
||||
test('非アクティブなWebhookはキューに追加されない', async () => {
|
||||
const webhook = await createWebhook({
|
||||
active: false,
|
||||
on: ['note'],
|
||||
});
|
||||
await service.enqueueUserWebhook(webhook.userId, 'note', { foo: 'bar' } as any);
|
||||
|
||||
expect(queueService.userWebhookDeliver).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('未許可のイベント種別が渡された場合はWebhookはキューに追加されない', async () => {
|
||||
const webhook1 = await createWebhook({
|
||||
active: true,
|
||||
on: [],
|
||||
});
|
||||
const webhook2 = await createWebhook({
|
||||
active: true,
|
||||
on: ['note'],
|
||||
});
|
||||
await service.enqueueUserWebhook(webhook1.userId, 'renote', { foo: 'bar' } as any);
|
||||
await service.enqueueUserWebhook(webhook2.userId, 'renote', { foo: 'bar' } as any);
|
||||
|
||||
expect(queueService.userWebhookDeliver).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('ユーザIDが異なるWebhookはキューに追加されない', async () => {
|
||||
const webhook = await createWebhook({
|
||||
active: true,
|
||||
on: ['note'],
|
||||
});
|
||||
await service.enqueueUserWebhook(idService.gen(), 'note', { foo: 'bar' } as any);
|
||||
|
||||
expect(queueService.userWebhookDeliver).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('混在した時、有効かつ許可されたイベント種別のみ', async () => {
|
||||
const userId = root.id;
|
||||
const webhook1 = await createWebhook({
|
||||
userId,
|
||||
active: true,
|
||||
on: ['note'],
|
||||
});
|
||||
const webhook2 = await createWebhook({
|
||||
userId,
|
||||
active: true,
|
||||
on: ['renote'],
|
||||
});
|
||||
const webhook3 = await createWebhook({
|
||||
userId,
|
||||
active: false,
|
||||
on: ['note'],
|
||||
});
|
||||
const webhook4 = await createWebhook({
|
||||
userId,
|
||||
active: false,
|
||||
on: ['renote'],
|
||||
});
|
||||
await service.enqueueUserWebhook(userId, 'note', { foo: 'bar' } as any);
|
||||
|
||||
expect(queueService.userWebhookDeliver).toHaveBeenCalledTimes(1);
|
||||
expect(queueService.userWebhookDeliver.mock.calls[0][0] as MiWebhook).toEqual(webhook1);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user