diff --git a/__tests__/unit/core/RPCPlugin.test.ts b/__tests__/unit/core/RPCPlugin.test.ts new file mode 100644 index 0000000..5fb797d --- /dev/null +++ b/__tests__/unit/core/RPCPlugin.test.ts @@ -0,0 +1,43 @@ +import { createHookRunner, RPCPlugin } from "@/core/RPCPlugin" +import type { CallIncomingCtx } from "@/core/RPCPlugin" + +describe('RPCPlugin.test', () => { + const plugin3 = { + onCallIncoming(ctx: CallIncomingCtx) { throw new Error() } + } as RPCPlugin; + const plugin4 = { + async onCallIncoming(ctx: CallIncomingCtx) { throw new Error() } + } as RPCPlugin; + + test('should be resolved', async () => { + const plugin1 = { + onCallIncoming: jest.fn(), + } as RPCPlugin; + const plugin2 = { + async onCallIncoming(ctx: CallIncomingCtx) { } + } as RPCPlugin; + + const plugins = [plugin1, plugin2]; + const hookRunner = createHookRunner(plugins, 'onCallIncoming'); + await hookRunner({} as any); + expect(plugin1.onCallIncoming).toHaveBeenCalled() + }) + test('should be resolved2', async () => { + const plugins = [] as RPCPlugin[]; + const hookRunner = createHookRunner(plugins, 'onCallIncoming'); + await hookRunner({} as any); + expect.assertions(0); + }) + + test('should be rejected1', async () => { + const plugins = [plugin3]; + const hookRunner = createHookRunner(plugins, 'onCallIncoming'); + await expect(hookRunner({} as any)).rejects.toThrow(Error) + }) + + test('should be rejected2', async () => { + const plugins = [plugin4]; + const hookRunner = createHookRunner(plugins, 'onCallIncoming'); + await expect(hookRunner({} as any)).rejects.toThrow(Error) + }) +}) \ No newline at end of file