Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

test(message): pin cursor and count rules of the message selection

Yudhi Armyndharis2971d43d6a1c
diff --git a/src/modules/message/message-window.spec.ts b/src/modules/message/message-window.spec.ts
index 817a70f74..ff7330974 100644
--- a/src/modules/message/message-window.spec.ts
+++ b/src/modules/message/message-window.spec.ts
@@ -131,6 +131,38 @@ describe('message-time selection', () => {
);
});
+ // The membership check is switched on by the selection itself. orderBy 'timestamp' does that alone,
+ // so the cases below keep the default order: each filter has to switch the check on in its own right.
+ it.each(['direction', 'type', 'since', 'until'] as const)(
+ 'rejects a cursor outside a selection narrowed only by %s',
+ async filter => {
+ const repo = ds.getRepository(Message);
+ await repo.update({ waMessageId: 'm10' }, { type: 'image' });
+ const row = (waMessageId: string): Promise<Message> => repo.findOneByOrFail({ waMessageId });
+ // m1 is outgoing and m11 is text; m0 is the oldest in message time and m200 is newer than 1010 s.
+ const cases = {
+ direction: [{ direction: MessageDirection.INCOMING }, await row('m1')],
+ type: [{ type: 'image' }, await row('m11')],
+ since: [{ since: 1050_000 }, await row('m0')],
+ until: [{ until: 1010_000 }, await row('m200')],
+ } as const;
+ const [selection, anchor] = cases[filter];
+
+ await expect(service.getMessages('s1', { ...selection, after: anchor.id })).rejects.toThrow(
+ 'Unknown cursor for this message selection',
+ );
+ },
+ );
+
+ it.each([
+ ['since', { since: 1000_000 }],
+ ['until', { until: 1060_000 }],
+ ] as const)('counts the rows without a message time when only %s bounds the selection', async (_bound, options) => {
+ const page = await service.getMessages('s1', options);
+
+ expect(page.unknownTimestampTotal).toBe(1);
+ });
+
it('keeps legacy ingestion order and unknown-time rows when new options are absent', async () => {
const legacy = await service.getMessages('s1');
expect(legacy.total).toBe(241);
diff --git a/src/modules/message/message.controller.spec.ts b/src/modules/message/message.controller.spec.ts
index 6310ff589..d1c20a2b9 100644
--- a/src/modules/message/message.controller.spec.ts
+++ b/src/modules/message/message.controller.spec.ts
@@ -48,6 +48,25 @@ describe('MessageController - message-time selection', () => {
}),
);
});
+ it('passes the type and message reference filters into the list', async () => {
+ await controller.getMessages(
+ 's1',
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ 'image',
+ 'wamid.ABC',
+ );
+ expect(getMessages).toHaveBeenCalledWith('s1', expect.objectContaining({ type: 'image', messageId: 'wamid.ABC' }));
+ });
it('rejects invalid selection before accessing storage', async () => {
await expect(
controller.getMessages(