Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
@@ -4,6 +4,7 @@ import {
|
||||
createAnalyticsEvent,
|
||||
createAnalyticsPageView,
|
||||
defaultAnalyticsPeriod,
|
||||
findAnalyticsPortalForTenant,
|
||||
findFeatureFlagByName,
|
||||
getAnalyticsEventFilterOptions,
|
||||
getAnalyticsEventList,
|
||||
@@ -103,6 +104,7 @@ function createAnalyticsClient(): AnalyticsClient {
|
||||
findMany: vi.fn().mockResolvedValue([{ id: "flag_1", name: "New home" }]),
|
||||
},
|
||||
portal: {
|
||||
findFirst: vi.fn().mockResolvedValue({ id: "portal_1", tenantId: "tenant_1" }),
|
||||
findMany: vi.fn().mockResolvedValue([{ id: "portal_1", title: "Docs portal" }]),
|
||||
},
|
||||
};
|
||||
@@ -162,7 +164,7 @@ describe("analytics overview aggregation", () => {
|
||||
expect.objectContaining({
|
||||
by: ["source"],
|
||||
where: { portalId: "portal_1", createdAt: { gte: new Date("2024-06-13T12:00:00.000Z") } },
|
||||
}),
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
@@ -179,7 +181,7 @@ describe("analytics overview aggregation", () => {
|
||||
expect.objectContaining({
|
||||
by: ["uniqueVisitorId"],
|
||||
where: { portalId: null, createdAt: { gte: new Date("2024-06-20T12:29:00.000Z") } },
|
||||
}),
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
@@ -197,7 +199,7 @@ describe("analytics overview aggregation", () => {
|
||||
expect.objectContaining({
|
||||
by: ["createdAt"],
|
||||
where: { portalId: "portal_2", createdAt: { gte: new Date("2024-01-02T03:04:05.000Z") } },
|
||||
}),
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
@@ -228,7 +230,7 @@ describe("analytics overview aggregation", () => {
|
||||
|
||||
const overview = await getAnalyticsOverview(
|
||||
{ period: "last-7-days", portalId: "portal_1", locale: "de", now: new Date("2024-06-20T12:00:00.000Z") },
|
||||
client,
|
||||
client
|
||||
);
|
||||
|
||||
expect(overview.charts.pageViewsAndUniqueVisitors).toEqual([
|
||||
@@ -254,7 +256,10 @@ describe("analytics overview aggregation", () => {
|
||||
return Promise.resolve([{ [field]: "high", _count: 7 }]);
|
||||
});
|
||||
|
||||
const overview = await getAnalyticsOverview({ period: "last-7-days", portalId: "portal_1", withUsers: true, now: new Date("2024-06-20T12:00:00.000Z") }, client);
|
||||
const overview = await getAnalyticsOverview(
|
||||
{ period: "last-7-days", portalId: "portal_1", withUsers: true, now: new Date("2024-06-20T12:00:00.000Z") },
|
||||
client
|
||||
);
|
||||
|
||||
expect(client.analyticsUniqueVisitor.groupBy).toHaveBeenCalledWith({
|
||||
by: ["userId"],
|
||||
@@ -274,6 +279,19 @@ describe("analytics overview aggregation", () => {
|
||||
});
|
||||
|
||||
describe("analytics list read models", () => {
|
||||
it("binds portal analytics reads to an exact tenant and portal pair", async () => {
|
||||
const client = createAnalyticsClient();
|
||||
|
||||
await expect(findAnalyticsPortalForTenant({ portalId: "portal_1", tenantId: "tenant_1" }, client)).resolves.toEqual({
|
||||
id: "portal_1",
|
||||
tenantId: "tenant_1",
|
||||
});
|
||||
expect(client.portal.findFirst).toHaveBeenCalledWith({
|
||||
where: { id: "portal_1", tenantId: "tenant_1" },
|
||||
select: { id: true, tenantId: true },
|
||||
});
|
||||
});
|
||||
|
||||
it("reads visitor pages with pagination, count filters, and relation counts", async () => {
|
||||
const client = createAnalyticsClient();
|
||||
const where = { source: "google" };
|
||||
@@ -409,7 +427,7 @@ describe("analytics write helpers", () => {
|
||||
portalUserId: "portal_user_2",
|
||||
},
|
||||
},
|
||||
client,
|
||||
client
|
||||
);
|
||||
|
||||
expect(client.analyticsUniqueVisitor.create).toHaveBeenCalledWith({
|
||||
@@ -447,7 +465,16 @@ describe("analytics write helpers", () => {
|
||||
it("does not update a visitor when no tracked fields changed", async () => {
|
||||
const client = createAnalyticsClient();
|
||||
|
||||
await updateAnalyticsUniqueVisitorSource(createVisitor(), { referrer: { source: "google", utm_medium: "cpc", utm_campaign: "spring" }, region: { country: "DE", city: "Berlin" }, userId: "user_1", portalUserId: "portal_user_1" }, client);
|
||||
await updateAnalyticsUniqueVisitorSource(
|
||||
createVisitor(),
|
||||
{
|
||||
referrer: { source: "google", utm_medium: "cpc", utm_campaign: "spring" },
|
||||
region: { country: "DE", city: "Berlin" },
|
||||
userId: "user_1",
|
||||
portalUserId: "portal_user_1",
|
||||
},
|
||||
client
|
||||
);
|
||||
|
||||
expect(client.analyticsUniqueVisitor.update).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -455,13 +482,23 @@ describe("analytics write helpers", () => {
|
||||
it("creates page views, events, reads settings, and looks up feature flags", async () => {
|
||||
const client = createAnalyticsClient();
|
||||
|
||||
await createAnalyticsPageView({ uniqueVisitorId: "visitor_1", url: "/docs?token=secret&utm_source=newsletter", route: "/docs", portalId: "portal_1", portalUserId: "portal_user_1" }, client);
|
||||
await createAnalyticsEvent({ uniqueVisitorId: "visitor_1", action: "click", category: "cta", url: "/event?email=ada@example.com", portalId: "portal_1", featureFlagId: "flag_1" }, client);
|
||||
await createAnalyticsPageView(
|
||||
{ uniqueVisitorId: "visitor_1", url: "/docs?token=secret&utm_source=newsletter", route: "/docs", portalId: "portal_1", portalUserId: "portal_user_1" },
|
||||
client
|
||||
);
|
||||
await createAnalyticsEvent(
|
||||
{ uniqueVisitorId: "visitor_1", action: "click", category: "cta", url: "/event?email=ada@example.com", portalId: "portal_1", featureFlagId: "flag_1" },
|
||||
client
|
||||
);
|
||||
await expect(getAnalyticsSettings(client)).resolves.toEqual({ id: "settings_1", public: false, ignorePages: "/health", onlyPages: "" });
|
||||
await expect(findFeatureFlagByName("new-home", client)).resolves.toEqual({ id: "flag_1" });
|
||||
|
||||
expect(client.analyticsPageView.create).toHaveBeenCalledWith({ data: { uniqueVisitorId: "visitor_1", url: "/docs?utm_source=newsletter", route: "/docs", portalId: "portal_1", portalUserId: "portal_user_1" } });
|
||||
expect(client.analyticsEvent.create).toHaveBeenCalledWith({ data: { uniqueVisitorId: "visitor_1", action: "click", category: "cta", url: "/event", portalId: "portal_1", featureFlagId: "flag_1" } });
|
||||
expect(client.analyticsPageView.create).toHaveBeenCalledWith({
|
||||
data: { uniqueVisitorId: "visitor_1", url: "/docs?utm_source=newsletter", route: "/docs", portalId: "portal_1", portalUserId: "portal_user_1" },
|
||||
});
|
||||
expect(client.analyticsEvent.create).toHaveBeenCalledWith({
|
||||
data: { uniqueVisitorId: "visitor_1", action: "click", category: "cta", url: "/event", portalId: "portal_1", featureFlagId: "flag_1" },
|
||||
});
|
||||
expect(client.analyticsSettings.findFirst).toHaveBeenCalledWith({ select: { public: true, ignorePages: true } });
|
||||
expect(client.featureFlag.findFirst).toHaveBeenCalledWith({ where: { name: "new-home" }, select: { id: true } });
|
||||
});
|
||||
@@ -470,7 +507,12 @@ describe("analytics write helpers", () => {
|
||||
const client = createAnalyticsClient();
|
||||
vi.mocked(client.analyticsSettings.findFirst).mockResolvedValueOnce(null);
|
||||
|
||||
await expect(getOrCreateAnalyticsSettings(client)).resolves.toEqual({ id: "settings_1", public: false, ignorePages: "/analytics,/admin/analytics", onlyPages: "" });
|
||||
await expect(getOrCreateAnalyticsSettings(client)).resolves.toEqual({
|
||||
id: "settings_1",
|
||||
public: false,
|
||||
ignorePages: "/analytics,/admin/analytics",
|
||||
onlyPages: "",
|
||||
});
|
||||
|
||||
expect(client.analyticsSettings.findFirst).toHaveBeenCalledWith({});
|
||||
expect(client.analyticsSettings.create).toHaveBeenCalledWith({ data: { public: false, ignorePages: "/analytics", onlyPages: "" } });
|
||||
@@ -519,7 +561,11 @@ describe("analytics write helpers", () => {
|
||||
expect(client.analyticsEvent.deleteMany).toHaveBeenCalledWith({});
|
||||
expect(client.analyticsPageView.deleteMany).toHaveBeenCalledWith({});
|
||||
expect(client.analyticsUniqueVisitor.deleteMany).toHaveBeenCalledWith({});
|
||||
expect(vi.mocked(client.analyticsEvent.deleteMany).mock.invocationCallOrder[0]).toBeLessThan(vi.mocked(client.analyticsPageView.deleteMany).mock.invocationCallOrder[0]);
|
||||
expect(vi.mocked(client.analyticsPageView.deleteMany).mock.invocationCallOrder[0]).toBeLessThan(vi.mocked(client.analyticsUniqueVisitor.deleteMany).mock.invocationCallOrder[0]);
|
||||
expect(vi.mocked(client.analyticsEvent.deleteMany).mock.invocationCallOrder[0]).toBeLessThan(
|
||||
vi.mocked(client.analyticsPageView.deleteMany).mock.invocationCallOrder[0]
|
||||
);
|
||||
expect(vi.mocked(client.analyticsPageView.deleteMany).mock.invocationCallOrder[0]).toBeLessThan(
|
||||
vi.mocked(client.analyticsUniqueVisitor.deleteMany).mock.invocationCallOrder[0]
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user