Schema: - 8 neue Profile-Felder fuer DiGA-Demographics (birthYear/gender/maritalStatus/ profession/bundesland/city + 2 consent-stamps demographicsConsentAt/ demographicsWithdrawnAt) - 4 Pro-Trial-Felder (proTrialStartedAt/ExpiresAt/Source/UsedAt) — Free-User bekommen 1 Woche Pro als Reward fuer DiGA-Daten-Pflege (siehe project_demographic_pro_trial_reward.md) - lyra_voice_id (Legend-only Voice-Picker) - diga_banner_dismissed_at (server-side persistence ueber Re-Install) - last_install_at (Streak-Logic survives Re-Install) - Migration 20260507_profile_demographics_and_trial: alle Felder optional, keine Backfill-Logik notwendig Endpoints (alle auth-protected, scope=me): - GET /api/profile/me/sos-insights - GET /api/profile/me/cooldown-history - GET /api/profile/me/approved-domains - POST /api/profile/me/install-event (track app re-installs) - POST /api/profile/me/diga-banner-dismiss - PATCH /api/profile/me/demographics (consent-stamp + re-grant-after-withdrawal in tx) - DELETE /api/profile/me/demographics (DSGVO right-to-be-forgotten) Plugin: - pro-trial-expiry-cron: 6h-Interval, conservative-fallback (revoke nur wenn kein stripeSubId), 60s initial-delay damit Server-boot nicht blockiert wird Tests: - vitest config + erste Test-Files (test-infrastructure setup) Memory: - feedback_demographics_user_initiated.md (Lyra darf NIE extrahieren) - project_demographic_pro_trial_reward.md (Pro-Trial-Reward-Mechanik) - project_profile_page_design.md (UI-Showpiece, eigene/fremde-Ansicht streng getrennt) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
/**
|
|
* Tests for install-event + diga-banner-dismiss DB layer.
|
|
* Both are minimal one-shot updates — but the timestamp behaviour
|
|
* must be correct (always-now, never-clear).
|
|
*/
|
|
import { describe, expect, it, vi, beforeEach } from "vitest";
|
|
|
|
const mocks = vi.hoisted(() => ({
|
|
profile: { update: vi.fn() },
|
|
}));
|
|
|
|
vi.mock("../../server/utils/prisma", () => ({
|
|
usePrisma: () => ({
|
|
profile: mocks.profile,
|
|
}),
|
|
}));
|
|
|
|
import {
|
|
dismissDigaBanner,
|
|
recordInstallEvent,
|
|
} from "../../server/db/profile";
|
|
|
|
const mockProfile = mocks.profile;
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
describe("recordInstallEvent", () => {
|
|
it("sets lastInstallAt = NOW for the given user", async () => {
|
|
mockProfile.update.mockResolvedValueOnce({});
|
|
await recordInstallEvent("user-1");
|
|
|
|
expect(mockProfile.update).toHaveBeenCalledWith({
|
|
where: { id: "user-1" },
|
|
data: expect.objectContaining({ lastInstallAt: expect.any(Date) }),
|
|
});
|
|
const data = mockProfile.update.mock.calls[0]?.[0]?.data as {
|
|
lastInstallAt: Date;
|
|
};
|
|
expect(Math.abs(data.lastInstallAt.getTime() - Date.now())).toBeLessThan(
|
|
5_000,
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("dismissDigaBanner", () => {
|
|
it("sets digaBannerDismissedAt = NOW for the given user", async () => {
|
|
mockProfile.update.mockResolvedValueOnce({});
|
|
await dismissDigaBanner("user-1");
|
|
|
|
expect(mockProfile.update).toHaveBeenCalledWith({
|
|
where: { id: "user-1" },
|
|
data: expect.objectContaining({
|
|
digaBannerDismissedAt: expect.any(Date),
|
|
}),
|
|
});
|
|
});
|
|
});
|