Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
+96
@@ -0,0 +1,96 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
type OnboardingPaginationDbMocks = {
|
||||
onboardingFindMany: ReturnType<typeof vi.fn>;
|
||||
onboardingCount: ReturnType<typeof vi.fn>;
|
||||
onboardingSessionFindMany: ReturnType<typeof vi.fn>;
|
||||
onboardingSessionCount: ReturnType<typeof vi.fn>;
|
||||
};
|
||||
|
||||
function getDbMocks(): OnboardingPaginationDbMocks {
|
||||
const store = globalThis as typeof globalThis & { __onboardingPaginationDbMocks__?: OnboardingPaginationDbMocks };
|
||||
store.__onboardingPaginationDbMocks__ ??= {
|
||||
onboardingFindMany: vi.fn(),
|
||||
onboardingCount: vi.fn(),
|
||||
onboardingSessionFindMany: vi.fn(),
|
||||
onboardingSessionCount: vi.fn(),
|
||||
};
|
||||
return store.__onboardingPaginationDbMocks__;
|
||||
}
|
||||
|
||||
vi.mock("~/utils/db.server", () => ({
|
||||
db: {
|
||||
onboarding: {
|
||||
findMany: getDbMocks().onboardingFindMany,
|
||||
count: getDbMocks().onboardingCount,
|
||||
},
|
||||
onboardingSession: {
|
||||
findMany: getDbMocks().onboardingSessionFindMany,
|
||||
count: getDbMocks().onboardingSessionCount,
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
import { getOnboardingsWithPagination } from "./onboarding.db.server";
|
||||
import { getOnboardingSessionsWithPagination } from "./onboardingSessions.db.server";
|
||||
|
||||
const dbMocks = getDbMocks();
|
||||
|
||||
describe("onboarding pagination queries", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
dbMocks.onboardingFindMany.mockResolvedValue([{ id: "onboarding_1" }]);
|
||||
dbMocks.onboardingCount.mockResolvedValue(21);
|
||||
dbMocks.onboardingSessionFindMany.mockResolvedValue([{ id: "session_1" }]);
|
||||
dbMocks.onboardingSessionCount.mockResolvedValue(12);
|
||||
});
|
||||
|
||||
it("fetches onboarding page rows and totals with stable query args", async () => {
|
||||
await expect(
|
||||
getOnboardingsWithPagination({
|
||||
where: { active: true },
|
||||
pagination: { page: 2, pageSize: 10 },
|
||||
})
|
||||
).resolves.toEqual({
|
||||
items: [{ id: "onboarding_1" }],
|
||||
pagination: { page: 2, pageSize: 10, totalItems: 21, totalPages: 3 },
|
||||
});
|
||||
|
||||
expect(dbMocks.onboardingFindMany).toHaveBeenCalledWith({
|
||||
where: { active: true },
|
||||
take: 10,
|
||||
skip: 10,
|
||||
include: { filters: { orderBy: { createdAt: "asc" } }, steps: { orderBy: { order: "asc" } }, sessions: true },
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
expect(dbMocks.onboardingCount).toHaveBeenCalledWith({ where: { active: true } });
|
||||
});
|
||||
|
||||
it("fetches onboarding session page rows and totals with stable query args", async () => {
|
||||
await expect(
|
||||
getOnboardingSessionsWithPagination({
|
||||
where: { tenantId: "tenant_1" },
|
||||
pagination: { page: 3, pageSize: 5 },
|
||||
})
|
||||
).resolves.toEqual({
|
||||
items: [{ id: "session_1" }],
|
||||
pagination: { page: 3, pageSize: 5, totalItems: 12, totalPages: 3 },
|
||||
});
|
||||
|
||||
expect(dbMocks.onboardingSessionFindMany).toHaveBeenCalledWith({
|
||||
where: { tenantId: "tenant_1" },
|
||||
take: 5,
|
||||
skip: 10,
|
||||
include: {
|
||||
onboarding: true,
|
||||
user: true,
|
||||
tenant: true,
|
||||
sessionSteps: { include: { step: true }, orderBy: { step: { order: "asc" } } },
|
||||
actions: true,
|
||||
matches: { include: { onboardingFilter: true } },
|
||||
},
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
expect(dbMocks.onboardingSessionCount).toHaveBeenCalledWith({ where: { tenantId: "tenant_1" } });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user