Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
test(message): pin the hourly prune of send idempotency keys
Yudhi Armyndharisd2e914a21ed2
diff --git a/src/modules/message/idempotency/send-idempotency.service.spec.ts b/src/modules/message/idempotency/send-idempotency.service.spec.tsindex 0f90badf6..e0a925d71 100644--- a/src/modules/message/idempotency/send-idempotency.service.spec.ts+++ b/src/modules/message/idempotency/send-idempotency.service.spec.ts@@ -148,6 +148,33 @@ describe('SendIdempotencyService (sqlite)', () => {await ds.query('DROP TABLE "send_idempotency_keys"');await expect(service.claim(input)).rejects.toThrow(/no such table/);});++ // The sweep is the only cleanup for keys that are never claimed again: without it every distinct+ // key a client ever used stays in the table, with its stored response, for good.+ describe('hourly prune', () => {+ const hour = 60 * 60 * 1000;++ afterEach(() => {+ jest.useRealTimers();+ });++ it('starts at module init, runs every hour, and stops at module destroy', () => {+ jest.useFakeTimers();+ const prune = jest.spyOn(service, 'pruneExpired').mockResolvedValue(0);++ service.onModuleInit();+ jest.advanceTimersByTime(hour - 1);+ expect(prune).not.toHaveBeenCalled();+ jest.advanceTimersByTime(1);+ expect(prune).toHaveBeenCalledTimes(1);+ jest.advanceTimersByTime(hour);+ expect(prune).toHaveBeenCalledTimes(2);++ service.onModuleDestroy();+ jest.advanceTimersByTime(2 * hour);+ expect(prune).toHaveBeenCalledTimes(2);+ });+ });});describe('isValidIdempotencyKey', () => {