mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
Group 245 flat integration tests and 25 loose unit tests into
discoverable subdirectories per spec section 6:
integration/tools/{image,video,audio,document,data}/ (156 files)
integration/platform/ (64 files)
integration/generated/ (14 files)
integration/security/ (10 files)
unit/security/ (8 files, new subdir)
unit/api/ (7 files moved in)
unit/web/ (3 files moved in)
unit/shared/ (6 files moved in)
unit/image-engine/ (1 file moved in)
All moves via git mv (history preserved). Relative imports repaired
for both depth levels (platform/generated/security = +1, tools/ = +2):
static from-imports, dynamic import() calls, vi.mock() paths,
import.meta.dirname joins, and __dirname joins.
Vitest discovery unchanged (no test.include in config, recursive glob
matches subdirs, shard-by-hash unaffected). test-server.ts and
tool-route-drift.test.ts stay at integration root. fixtures/ untouched.
Parity gate: 13189 passing test names before = 13189 after (0 dropped).
124 lines
2.8 KiB
TypeScript
124 lines
2.8 KiB
TypeScript
import { isConsentEnabled, shouldShowConsent } from "@snapotter/shared";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
describe("shouldShowConsent", () => {
|
|
it("returns false when server has analytics disabled", () => {
|
|
expect(
|
|
shouldShowConsent(
|
|
{
|
|
analyticsEnabled: null,
|
|
analyticsConsentShownAt: null,
|
|
analyticsConsentRemindAt: null,
|
|
},
|
|
false,
|
|
),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("returns true for a fresh user who has never been asked", () => {
|
|
expect(
|
|
shouldShowConsent(
|
|
{
|
|
analyticsEnabled: null,
|
|
analyticsConsentShownAt: null,
|
|
analyticsConsentRemindAt: null,
|
|
},
|
|
true,
|
|
),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("returns false when user already opted in", () => {
|
|
expect(
|
|
shouldShowConsent(
|
|
{
|
|
analyticsEnabled: true,
|
|
analyticsConsentShownAt: Date.now(),
|
|
analyticsConsentRemindAt: null,
|
|
},
|
|
true,
|
|
),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("returns false when user explicitly declined", () => {
|
|
expect(
|
|
shouldShowConsent(
|
|
{
|
|
analyticsEnabled: false,
|
|
analyticsConsentShownAt: Date.now(),
|
|
analyticsConsentRemindAt: null,
|
|
},
|
|
true,
|
|
),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("returns false when remind-at is in the future", () => {
|
|
expect(
|
|
shouldShowConsent(
|
|
{
|
|
analyticsEnabled: null,
|
|
analyticsConsentShownAt: Date.now() - 86400000,
|
|
analyticsConsentRemindAt: Date.now() + 86400000,
|
|
},
|
|
true,
|
|
),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("returns true when remind-at has passed", () => {
|
|
expect(
|
|
shouldShowConsent(
|
|
{
|
|
analyticsEnabled: null,
|
|
analyticsConsentShownAt: Date.now() - 86400000 * 8,
|
|
analyticsConsentRemindAt: Date.now() - 86400000,
|
|
},
|
|
true,
|
|
),
|
|
).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("isConsentEnabled", () => {
|
|
it("returns false when server disabled", () => {
|
|
expect(
|
|
isConsentEnabled(
|
|
{
|
|
analyticsEnabled: true,
|
|
analyticsConsentShownAt: Date.now(),
|
|
analyticsConsentRemindAt: null,
|
|
},
|
|
false,
|
|
),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("returns false when user has not consented", () => {
|
|
expect(
|
|
isConsentEnabled(
|
|
{
|
|
analyticsEnabled: null,
|
|
analyticsConsentShownAt: null,
|
|
analyticsConsentRemindAt: null,
|
|
},
|
|
true,
|
|
),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("returns true when user opted in and server enabled", () => {
|
|
expect(
|
|
isConsentEnabled(
|
|
{
|
|
analyticsEnabled: true,
|
|
analyticsConsentShownAt: Date.now(),
|
|
analyticsConsentRemindAt: null,
|
|
},
|
|
true,
|
|
),
|
|
).toBe(true);
|
|
});
|
|
});
|