Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
test(engine): pin each chat-state field to its own source
Yudhi Armyndharis30a0bc95e100
diff --git a/src/engine/adapters/baileys-session-store.spec.ts b/src/engine/adapters/baileys-session-store.spec.tsindex 5faa75b35..29b6b13f2 100644--- a/src/engine/adapters/baileys-session-store.spec.ts+++ b/src/engine/adapters/baileys-session-store.spec.ts@@ -42,12 +42,30 @@ describe('BaileysSessionStore', () => {expect(store.findContact('[email protected]')?.pushName).toBe('Bob');});- describe('pinned and muted state', () => {+ describe('archived, pinned and muted state', () => {+ // A fresh store per call: upsertChats MERGES, so reusing one store lets an absent-field case+ // re-read a value a prior call set, and the default-to-false path would never run.const chatFor = (over: Record<string, unknown>) => {- store.upsertChats([{ id: '[email protected]', name: 'Alice', ...over }]);- return store.listChats()[0];+ const s = new BaileysSessionStore();+ s.upsertChats([{ id: '[email protected]', name: 'Alice', ...over }]);+ return s.listChats()[0];};+ it('maps archived, pinned and muted each from its own field', () => {+ // No Baileys case asserted archived: true before, so `archived: c.archived ?? false` could be+ // a constant false and stay green. Mixed values pin each flag to its own source.+ expect(chatFor({ archived: true, pinned: 0, muteEndTime: 0 })).toMatchObject({+ archived: true,+ pinned: false,+ muted: false,+ });+ expect(chatFor({ archived: false, pinned: 2, muteEndTime: 0 })).toMatchObject({+ archived: false,+ pinned: true,+ muted: false,+ });+ });+it('reads a pin as a flag, though Baileys reports it as an order', () => {// proto.IConversation.pinned is a NUMBER — its position among pinned chats, not a boolean.expect(chatFor({ pinned: 2 }).pinned).toBe(true);diff --git a/src/engine/adapters/wwebjs-chat-state.spec.ts b/src/engine/adapters/wwebjs-chat-state.spec.tsindex bcf72e510..55c48e376 100644--- a/src/engine/adapters/wwebjs-chat-state.spec.ts+++ b/src/engine/adapters/wwebjs-chat-state.spec.ts@@ -65,6 +65,22 @@ describe('WwebjsChats.getChats chat state', () => {const summary = await listWith({ isMuted: false, muteExpiration: 1_700_000_000 });expect(summary.muted).toBe(false);});++ // The all-true and all-false cases above stay green if a mapper reads archived off pinned, or+ // muted off the wrong flag. These mixed cases pin each field to its own source: the first breaks+ // an archived/pinned swap, the second breaks muted reading either boolean.+ it('maps archived, pinned and muted each from its own field', async () => {+ expect(await listWith({ archived: true, pinned: false, isMuted: false })).toMatchObject({+ archived: true,+ pinned: false,+ muted: false,+ });+ expect(await listWith({ archived: false, pinned: false, isMuted: true })).toMatchObject({+ archived: false,+ pinned: false,+ muted: true,+ });+ });});describe('WwebjsLabels.getChatsByLabel chat state', () => {@@ -83,4 +99,17 @@ describe('WwebjsLabels.getChatsByLabel chat state', () => {const summary = await listWith({});expect(summary).toMatchObject({ archived: false, pinned: false, muted: false });});++ it('maps archived, pinned and muted each from its own field', async () => {+ expect(await listWith({ archived: true, pinned: false, isMuted: false })).toMatchObject({+ archived: true,+ pinned: false,+ muted: false,+ });+ expect(await listWith({ archived: false, pinned: false, isMuted: true })).toMatchObject({+ archived: false,+ pinned: false,+ muted: true,+ });+ });});