fix: Add missing default mock for updateMany in coordinator-integration tests
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
The default mock return value for updateMany was missing from beforeEach, causing tests to fail when the service called updateMany and checked count. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -58,7 +58,10 @@ describe("CoordinatorIntegrationService", () => {
|
|||||||
create: vi.fn(),
|
create: vi.fn(),
|
||||||
findUnique: vi.fn(),
|
findUnique: vi.fn(),
|
||||||
update: vi.fn(),
|
update: vi.fn(),
|
||||||
|
updateMany: vi.fn(),
|
||||||
},
|
},
|
||||||
|
$transaction: vi.fn(),
|
||||||
|
$queryRaw: vi.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
const mockJobEventsService = {
|
const mockJobEventsService = {
|
||||||
@@ -97,6 +100,9 @@ describe("CoordinatorIntegrationService", () => {
|
|||||||
jobEventsService = module.get<JobEventsService>(JobEventsService);
|
jobEventsService = module.get<JobEventsService>(JobEventsService);
|
||||||
heraldService = module.get<HeraldService>(HeraldService);
|
heraldService = module.get<HeraldService>(HeraldService);
|
||||||
bullMqService = module.get<BullMqService>(BullMqService);
|
bullMqService = module.get<BullMqService>(BullMqService);
|
||||||
|
|
||||||
|
// Set default mock return values
|
||||||
|
mockPrismaService.runnerJob.updateMany.mockResolvedValue({ count: 1 });
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("createJob", () => {
|
describe("createJob", () => {
|
||||||
@@ -145,8 +151,26 @@ describe("CoordinatorIntegrationService", () => {
|
|||||||
it("should update job status to RUNNING", async () => {
|
it("should update job status to RUNNING", async () => {
|
||||||
const updatedJob = { ...mockJob, status: RunnerJobStatus.RUNNING, startedAt: new Date() };
|
const updatedJob = { ...mockJob, status: RunnerJobStatus.RUNNING, startedAt: new Date() };
|
||||||
|
|
||||||
mockPrismaService.runnerJob.findUnique.mockResolvedValue(mockJob);
|
// Mock transaction that passes through the callback
|
||||||
mockPrismaService.runnerJob.update.mockResolvedValue(updatedJob);
|
mockPrismaService.$transaction.mockImplementation(async (callback) => {
|
||||||
|
const mockTx = {
|
||||||
|
$queryRaw: vi
|
||||||
|
.fn()
|
||||||
|
.mockResolvedValue([
|
||||||
|
{
|
||||||
|
id: mockJob.id,
|
||||||
|
status: mockJob.status,
|
||||||
|
workspace_id: mockJob.workspaceId,
|
||||||
|
version: 1,
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
runnerJob: {
|
||||||
|
update: vi.fn().mockResolvedValue(updatedJob),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return callback(mockTx);
|
||||||
|
});
|
||||||
|
|
||||||
mockJobEventsService.emitJobStarted.mockResolvedValue(mockEvent);
|
mockJobEventsService.emitJobStarted.mockResolvedValue(mockEvent);
|
||||||
mockHeraldService.broadcastJobEvent.mockResolvedValue(undefined);
|
mockHeraldService.broadcastJobEvent.mockResolvedValue(undefined);
|
||||||
|
|
||||||
@@ -160,7 +184,16 @@ describe("CoordinatorIntegrationService", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should throw NotFoundException if job does not exist", async () => {
|
it("should throw NotFoundException if job does not exist", async () => {
|
||||||
mockPrismaService.runnerJob.findUnique.mockResolvedValue(null);
|
// Mock transaction with empty result
|
||||||
|
mockPrismaService.$transaction.mockImplementation(async (callback) => {
|
||||||
|
const mockTx = {
|
||||||
|
$queryRaw: vi.fn().mockResolvedValue([]),
|
||||||
|
runnerJob: {
|
||||||
|
update: vi.fn(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return callback(mockTx);
|
||||||
|
});
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
service.updateJobStatus("non-existent", { status: "RUNNING" as const })
|
service.updateJobStatus("non-existent", { status: "RUNNING" as const })
|
||||||
@@ -168,8 +201,25 @@ describe("CoordinatorIntegrationService", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should throw BadRequestException for invalid status transition", async () => {
|
it("should throw BadRequestException for invalid status transition", async () => {
|
||||||
const completedJob = { ...mockJob, status: RunnerJobStatus.COMPLETED };
|
// Mock transaction with completed job
|
||||||
mockPrismaService.runnerJob.findUnique.mockResolvedValue(completedJob);
|
mockPrismaService.$transaction.mockImplementation(async (callback) => {
|
||||||
|
const mockTx = {
|
||||||
|
$queryRaw: vi
|
||||||
|
.fn()
|
||||||
|
.mockResolvedValue([
|
||||||
|
{
|
||||||
|
id: mockJob.id,
|
||||||
|
status: RunnerJobStatus.COMPLETED,
|
||||||
|
workspace_id: mockJob.workspaceId,
|
||||||
|
version: 1,
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
runnerJob: {
|
||||||
|
update: vi.fn(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return callback(mockTx);
|
||||||
|
});
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
service.updateJobStatus("job-123", { status: "RUNNING" as const })
|
service.updateJobStatus("job-123", { status: "RUNNING" as const })
|
||||||
@@ -179,11 +229,12 @@ describe("CoordinatorIntegrationService", () => {
|
|||||||
|
|
||||||
describe("updateJobProgress", () => {
|
describe("updateJobProgress", () => {
|
||||||
it("should update job progress percentage", async () => {
|
it("should update job progress percentage", async () => {
|
||||||
const runningJob = { ...mockJob, status: RunnerJobStatus.RUNNING };
|
const runningJob = { ...mockJob, status: RunnerJobStatus.RUNNING, version: 1 };
|
||||||
const updatedJob = { ...runningJob, progressPercent: 50 };
|
const updatedJob = { ...runningJob, progressPercent: 50, version: 2 };
|
||||||
|
|
||||||
mockPrismaService.runnerJob.findUnique.mockResolvedValue(runningJob);
|
mockPrismaService.runnerJob.findUnique.mockResolvedValue(runningJob);
|
||||||
mockPrismaService.runnerJob.update.mockResolvedValue(updatedJob);
|
mockPrismaService.runnerJob.updateMany.mockResolvedValue({ count: 1 });
|
||||||
|
mockPrismaService.runnerJob.findUnique.mockResolvedValue(updatedJob);
|
||||||
mockJobEventsService.emitEvent.mockResolvedValue(mockEvent);
|
mockJobEventsService.emitEvent.mockResolvedValue(mockEvent);
|
||||||
|
|
||||||
const result = await service.updateJobProgress("job-123", {
|
const result = await service.updateJobProgress("job-123", {
|
||||||
@@ -217,8 +268,26 @@ describe("CoordinatorIntegrationService", () => {
|
|||||||
completedAt: new Date(),
|
completedAt: new Date(),
|
||||||
};
|
};
|
||||||
|
|
||||||
mockPrismaService.runnerJob.findUnique.mockResolvedValue(runningJob);
|
// Mock transaction with running job
|
||||||
mockPrismaService.runnerJob.update.mockResolvedValue(completedJob);
|
mockPrismaService.$transaction.mockImplementation(async (callback) => {
|
||||||
|
const mockTx = {
|
||||||
|
$queryRaw: vi
|
||||||
|
.fn()
|
||||||
|
.mockResolvedValue([
|
||||||
|
{
|
||||||
|
id: mockJob.id,
|
||||||
|
status: RunnerJobStatus.RUNNING,
|
||||||
|
workspace_id: mockJob.workspaceId,
|
||||||
|
version: 1,
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
runnerJob: {
|
||||||
|
update: vi.fn().mockResolvedValue(completedJob),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return callback(mockTx);
|
||||||
|
});
|
||||||
|
|
||||||
mockJobEventsService.emitJobCompleted.mockResolvedValue(mockEvent);
|
mockJobEventsService.emitJobCompleted.mockResolvedValue(mockEvent);
|
||||||
mockHeraldService.broadcastJobEvent.mockResolvedValue(undefined);
|
mockHeraldService.broadcastJobEvent.mockResolvedValue(undefined);
|
||||||
|
|
||||||
@@ -243,8 +312,26 @@ describe("CoordinatorIntegrationService", () => {
|
|||||||
completedAt: new Date(),
|
completedAt: new Date(),
|
||||||
};
|
};
|
||||||
|
|
||||||
mockPrismaService.runnerJob.findUnique.mockResolvedValue(runningJob);
|
// Mock transaction with running job
|
||||||
mockPrismaService.runnerJob.update.mockResolvedValue(failedJob);
|
mockPrismaService.$transaction.mockImplementation(async (callback) => {
|
||||||
|
const mockTx = {
|
||||||
|
$queryRaw: vi
|
||||||
|
.fn()
|
||||||
|
.mockResolvedValue([
|
||||||
|
{
|
||||||
|
id: mockJob.id,
|
||||||
|
status: RunnerJobStatus.RUNNING,
|
||||||
|
workspace_id: mockJob.workspaceId,
|
||||||
|
version: 1,
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
runnerJob: {
|
||||||
|
update: vi.fn().mockResolvedValue(failedJob),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return callback(mockTx);
|
||||||
|
});
|
||||||
|
|
||||||
mockJobEventsService.emitJobFailed.mockResolvedValue(mockEvent);
|
mockJobEventsService.emitJobFailed.mockResolvedValue(mockEvent);
|
||||||
mockHeraldService.broadcastJobEvent.mockResolvedValue(undefined);
|
mockHeraldService.broadcastJobEvent.mockResolvedValue(undefined);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user