Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/lib/availability/availability-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ const MAX_AVAILABILITY_QUERY_RANGE_MS =
MAX_BUCKETS_HARD_LIMIT * MAX_BUCKET_SIZE_MINUTES * 60 * 1000;

function floorToUtcMinute(date: Date): Date {
return new Date(Date.UTC(
date.getUTCFullYear(),
date.getUTCMonth(),
date.getUTCDate(),
date.getUTCHours(),
date.getUTCMinutes(),
0,
0
));
return new Date(
Date.UTC(
date.getUTCFullYear(),
date.getUTCMonth(),
date.getUTCDate(),
date.getUTCHours(),
date.getUTCMinutes(),
0,
0
)
);
}

export class AvailabilityQueryValidationError extends Error {
Expand Down
21 changes: 12 additions & 9 deletions tests/unit/lib/availability/projection-worker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ describe("availability projection-worker", () => {
}
return [];
});
const transactionMock = vi.fn(async (fn: (tx: { execute: typeof executeMock }) => Promise<number>) =>
fn({ execute: executeMock })
const transactionMock = vi.fn(
async (fn: (tx: { execute: typeof executeMock }) => Promise<number>) =>
fn({ execute: executeMock })
);

vi.doMock("@/drizzle/db", () => ({
Expand All @@ -97,9 +98,9 @@ describe("availability projection-worker", () => {
expect(texts.some((t) => t.includes("insert into avail_bucket_1m"))).toBe(true);
expect(texts.some((t) => t.includes("insert into avail_current"))).toBe(true);
expect(texts.some((t) => t.includes("15 * interval '1 minute'"))).toBe(true);
expect(texts.some((t) => t.includes("update outbox_events") && t.includes("published_at"))).toBe(
true
);
expect(
texts.some((t) => t.includes("update outbox_events") && t.includes("published_at"))
).toBe(true);
});

it("processBatch 对重复 request 不重复计数", async () => {
Expand All @@ -125,8 +126,9 @@ describe("availability projection-worker", () => {
}
return [];
});
const transactionMock = vi.fn(async (fn: (tx: { execute: typeof executeMock }) => Promise<number>) =>
fn({ execute: executeMock })
const transactionMock = vi.fn(
async (fn: (tx: { execute: typeof executeMock }) => Promise<number>) =>
fn({ execute: executeMock })
);

vi.doMock("@/drizzle/db", () => ({
Expand Down Expand Up @@ -165,8 +167,9 @@ describe("availability projection-worker", () => {
}
return [];
});
const transactionMock = vi.fn(async (fn: (tx: { execute: typeof executeMock }) => Promise<number>) =>
fn({ execute: executeMock })
const transactionMock = vi.fn(
async (fn: (tx: { execute: typeof executeMock }) => Promise<number>) =>
fn({ execute: executeMock })
);

vi.doMock("@/drizzle/db", () => ({
Expand Down