Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

test(plugins): cover reply lazy-resolution and absent-sessions default

rmyndharisa0b41a6eadbf
diff --git a/src/core/plugins/plugin-capability.spec.ts b/src/core/plugins/plugin-capability.spec.ts
index b22b8b3d0..9453114b6 100644
--- a/src/core/plugins/plugin-capability.spec.ts
+++ b/src/core/plugins/plugin-capability.spec.ts
@@ -64,6 +64,7 @@ describe('PluginLoaderService capability facade — ctx.messages', () => {
it('messages.reply delegates to MessageService.reply', async () => {
const ctx = contextFor(makePlugin(['*']));
await ctx.messages.reply('sess-1', '[email protected]', 'quoted-id', 'pong');
+ expect(moduleRef.get).toHaveBeenCalledWith(MessageService, { strict: false });
expect(messageService.reply).toHaveBeenCalledWith('sess-1', {
chatId: '[email protected]',
quotedMessageId: 'quoted-id',
@@ -71,6 +72,12 @@ describe('PluginLoaderService capability facade — ctx.messages', () => {
});
});
+ it('allows any session when manifest.sessions is absent (defaults to all)', async () => {
+ const ctx = contextFor(makePlugin()); // no sessions field
+ await ctx.messages.sendText('any-session', '[email protected]', 'hi');
+ expect(messageService.sendText).toHaveBeenCalledWith('any-session', { chatId: '[email protected]', text: 'hi' });
+ });
+
it('rejects an out-of-scope session BEFORE resolving the service', async () => {
const ctx = contextFor(makePlugin(['allowed-session']));
await expect(ctx.messages.sendText('other-session', '[email protected]', 'hi')).rejects.toBeInstanceOf(
diff --git a/src/core/plugins/plugin-loader.service.ts b/src/core/plugins/plugin-loader.service.ts
index 04f47aadb..c50e545df 100644
--- a/src/core/plugins/plugin-loader.service.ts
+++ b/src/core/plugins/plugin-loader.service.ts
@@ -43,8 +43,8 @@ export class PluginLoaderService implements OnModuleInit {
private readonly configService: ConfigService,
private readonly hookManager: HookManager,
private readonly pluginStorage: PluginStorageService,
- // Resolves MessageService/SessionService lazily inside capability verbs. ModuleRef
- // (not constructor injection) breaks the provider cycle
+ // Resolves MessageService/SessionService lazily inside capability verbs. ModuleRef is used
+ // instead of constructor injection to avoid the provider cycle
// PluginLoaderService -> SessionService -> EngineFactory -> PluginLoaderService.
private readonly moduleRef: ModuleRef,
) {