Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

test(engine): pin the chat state stamp bound just above a minute

Yudhi Armyndharis5684b44d809e
diff --git a/src/engine/adapters/baileys-chat-state-store.service.spec.ts b/src/engine/adapters/baileys-chat-state-store.service.spec.ts
index 14c56f4f9..cf82f98e6 100644
--- a/src/engine/adapters/baileys-chat-state-store.service.spec.ts
+++ b/src/engine/adapters/baileys-chat-state-store.service.spec.ts
@@ -836,6 +836,20 @@ describe('ChatStateStoreService', () => {
expect(mergeTwinStates([svc.get('s', PHONE)!, svc.get('s', LID)!])).toMatchObject({ pinned: true });
});
+ it.each([
+ ['61 s', 61_000],
+ ['5 min', 5 * 60_000],
+ ['59 min', 59 * 60_000],
+ ])('follows the clock again after it steps back %s', async (_step, lead) => {
+ const repo = makeRepo();
+ const svc = svcWith(repo);
+ fakeDate(T + lead);
+ await svc.remember('s', PHONE, { pinned: false });
+ jest.setSystemTime(T);
+ await svc.remember('s', LID, { pinned: true });
+ expect(repo.rows.get(KEY('s', LID))!.updatedAt.getTime()).toBe(T);
+ });
+
it('follows the clock again after it steps back hours, so a twin written after a restart ranks newer', async () => {
const repo = makeRepo();
fakeDate(T + 7 * 3_600_000); // booted with the clock seven hours ahead