repository.test.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { describe, expect, it, vi } from "vitest";
  2. process.env.DSN = "";
  3. vi.mock("@/drizzle/db", () => ({
  4. db: {
  5. select: vi.fn(() => ({ from: vi.fn(() => ({ where: vi.fn(async () => []) })) })),
  6. execute: vi.fn(async () => []),
  7. },
  8. }));
  9. vi.mock("drizzle-orm", async (importOriginal) => {
  10. const actual = await importOriginal<typeof import("drizzle-orm")>();
  11. return {
  12. ...actual,
  13. and: vi.fn((...args: unknown[]) => args),
  14. eq: vi.fn((...args: unknown[]) => args),
  15. gte: vi.fn((...args: unknown[]) => args),
  16. lt: vi.fn((...args: unknown[]) => args),
  17. inArray: vi.fn((...args: unknown[]) => args),
  18. };
  19. });
  20. vi.mock("@/drizzle/schema", () => ({
  21. usageLedger: {
  22. userId: "user_id",
  23. key: "key",
  24. finalProviderId: "final_provider_id",
  25. costUsd: "cost_usd",
  26. createdAt: "created_at",
  27. blockedBy: "blocked_by",
  28. },
  29. }));
  30. vi.mock("@/repository/_shared/ledger-conditions", () => ({
  31. LEDGER_BILLING_CONDITION: {},
  32. }));
  33. const repo = await import("@/repository/usage-ledger");
  34. describe("usage-ledger repository", () => {
  35. it("exports sumLedgerCostInTimeRange", () => {
  36. expect(typeof repo.sumLedgerCostInTimeRange).toBe("function");
  37. });
  38. it("exports sumLedgerTotalCost", () => {
  39. expect(typeof repo.sumLedgerTotalCost).toBe("function");
  40. });
  41. it("exports sumLedgerTotalCostBatch", () => {
  42. expect(typeof repo.sumLedgerTotalCostBatch).toBe("function");
  43. });
  44. it("exports countLedgerRequestsInTimeRange", () => {
  45. expect(typeof repo.countLedgerRequestsInTimeRange).toBe("function");
  46. });
  47. });