Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

test(message): pin the startup reap count to rows actually failed

Yudhi Armyndharis8f02c59be1b5
diff --git a/src/modules/message/bulk-message.service.spec.ts b/src/modules/message/bulk-message.service.spec.ts
index 30a2faa4b..d4987e31d 100644
--- a/src/modules/message/bulk-message.service.spec.ts
+++ b/src/modules/message/bulk-message.service.spec.ts
@@ -1,5 +1,5 @@
import { Test, TestingModule } from '@nestjs/testing';
-import { BadRequestException, HttpException, PayloadTooLargeException } from '@nestjs/common';
+import { BadRequestException, HttpException, Logger, PayloadTooLargeException } from '@nestjs/common';
import { getRepositoryToken } from '@nestjs/typeorm';
import { In, Not } from 'typeorm';
import {
@@ -117,6 +117,23 @@ describe('BulkMessageService.onApplicationBootstrap', () => {
expect(repo.update).not.toHaveBeenCalled();
});
+ it('counts on startup only the batches the guarded update actually failed', async () => {
+ const stale = { id: 'b-done', status: BatchStatus.PROCESSING, messages: [] };
+ const orphan = { id: 'b-dead', status: BatchStatus.PROCESSING, messages: [] };
+ repo.find.mockResolvedValue([stale, orphan]);
+ repo.update.mockImplementation((where: { id: string }) =>
+ Promise.resolve({ affected: where.id === 'b-dead' ? 1 : 0 }),
+ );
+ const warn = jest.spyOn((service as unknown as { logger: Logger }).logger, 'warn').mockImplementation();
+
+ await service.onApplicationBootstrap();
+
+ expect(repo.update).toHaveBeenCalledTimes(2);
+ expect(warn).toHaveBeenCalledWith(
+ 'Marked 1 orphaned PROCESSING batch(es) FAILED on startup (interrupted by a restart)',
+ );
+ });
+
/**
* The takeover path's reconcile: adopting a session from a lapsed node must fail THAT session's
* stuck batches (same no-auto-resume policy as boot — the dead node's already-sent messages are