feat(core-analytics): add IAnalytics interface, types, and NoopAnalytics
Replaces generator placeholder with IAnalytics interface (track, identify, pageView, flush), AnalyticsAttributeValue + AnalyticsUser types, and NoopAnalytics implementation. Adds sibling tests covering all four methods with 100% coverage. All conformance + coverage gates pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
54
packages/core-analytics/src/noop-analytics.test.ts
Normal file
54
packages/core-analytics/src/noop-analytics.test.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { NoopAnalytics } from "@/noop-analytics";
|
||||
|
||||
describe("NoopAnalytics", () => {
|
||||
it("track() does not throw with event name only", () => {
|
||||
const analytics = new NoopAnalytics();
|
||||
expect(() => analytics.track("page_viewed")).not.toThrow();
|
||||
});
|
||||
|
||||
it("track() does not throw with event name and attributes", () => {
|
||||
const analytics = new NoopAnalytics();
|
||||
expect(() =>
|
||||
analytics.track("button_clicked", {
|
||||
label: "signup",
|
||||
count: 1,
|
||||
active: true,
|
||||
}),
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it("identify() does not throw with user only", () => {
|
||||
const analytics = new NoopAnalytics();
|
||||
expect(() => analytics.identify({ id: "user-123" })).not.toThrow();
|
||||
});
|
||||
|
||||
it("identify() does not throw with user and attributes", () => {
|
||||
const analytics = new NoopAnalytics();
|
||||
expect(() =>
|
||||
analytics.identify({ id: "user-123" }, { plan: "pro", trial: false }),
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it("pageView() does not throw with path only", () => {
|
||||
const analytics = new NoopAnalytics();
|
||||
expect(() => analytics.pageView("/dashboard")).not.toThrow();
|
||||
});
|
||||
|
||||
it("pageView() does not throw with path and attributes", () => {
|
||||
const analytics = new NoopAnalytics();
|
||||
expect(() =>
|
||||
analytics.pageView("/dashboard", { referrer: "/home", duration: 120 }),
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it("flush() resolves without throwing", async () => {
|
||||
const analytics = new NoopAnalytics();
|
||||
await expect(analytics.flush()).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it("flush() returns a Promise", () => {
|
||||
const analytics = new NoopAnalytics();
|
||||
expect(analytics.flush()).toBeInstanceOf(Promise);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user