Merge pull request #534 from paperclipai/fix/approval-service-idempotency
Fix approvals service idempotency test
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { approvalService } from "../services/approvals.js";
|
import { approvalService } from "../services/approvals.ts";
|
||||||
|
|
||||||
const mockAgentService = vi.hoisted(() => ({
|
const mockAgentService = vi.hoisted(() => ({
|
||||||
activatePendingApproval: vi.fn(),
|
activatePendingApproval: vi.fn(),
|
||||||
@@ -38,15 +38,12 @@ function createApproval(status: string): ApprovalRecord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createDbStub(selectResults: ApprovalRecord[][], updateResults: ApprovalRecord[]) {
|
function createDbStub(selectResults: ApprovalRecord[][], updateResults: ApprovalRecord[]) {
|
||||||
const selectWhere = vi.fn();
|
const pendingSelectResults = [...selectResults];
|
||||||
for (const result of selectResults) {
|
const selectWhere = vi.fn(async () => pendingSelectResults.shift() ?? []);
|
||||||
selectWhere.mockResolvedValueOnce(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
const from = vi.fn(() => ({ where: selectWhere }));
|
const from = vi.fn(() => ({ where: selectWhere }));
|
||||||
const select = vi.fn(() => ({ from }));
|
const select = vi.fn(() => ({ from }));
|
||||||
|
|
||||||
const returning = vi.fn().mockResolvedValue(updateResults);
|
const returning = vi.fn(async () => updateResults);
|
||||||
const updateWhere = vi.fn(() => ({ returning }));
|
const updateWhere = vi.fn(() => ({ returning }));
|
||||||
const set = vi.fn(() => ({ where: updateWhere }));
|
const set = vi.fn(() => ({ where: updateWhere }));
|
||||||
const update = vi.fn(() => ({ set }));
|
const update = vi.fn(() => ({ set }));
|
||||||
|
|||||||
Reference in New Issue
Block a user