import { describe, it, expect } from "bun:test"; import { parseConditionals, type ConditionalContext } from "./conditional-parser"; describe("parseConditionals", () => { const baseContext: ConditionalContext = { isAuthenticated: true, privilegeLevel: "user", userId: "test-user", currentDate: new Date("2025-06-01"), featureFlags: { "beta-feature": true }, env: { NODE_ENV: "development", VERCEL_ENV: "development" } }; it("should show content for authenticated users", () => { const html = `
Secret content
Secret content
Admin panel
Available until 2026
Available after 2024
2025 content
Beta content
Disabled content
Not authenticated content
Public content
Auth content
More public
Admin content
Regular content
"; const result = parseConditionals(html, baseContext); expect(result).toBe(html); }); it("should default to hiding unknown condition types", () => { const html = `Unknown type content
console.log('test');
console.log('test');");
});
it("should handle env condition with exact match", () => {
const html = `
Dev mode content
Prod content
Any env set
Should not show
Not production
Invalid format
The domain is localhost.
`; const result = parseConditionals(html, baseContext); expect(result).toContain("The domain is localhost."); expect(result).not.toContain("conditional-inline"); expect(result).not.toContain("data-condition-type"); }); it("should hide inline conditional when condition is false", () => { const html = `The domain is freno.me.
`; const result = parseConditionals(html, baseContext); expect(result).toBe("The domain is .
"); }); it("should handle inline auth conditionals", () => { const html = `Welcome back!
`; const result = parseConditionals(html, baseContext); expect(result).toContain("Welcome back!"); }); it("should handle multiple inline conditionals in same paragraph", () => { const html = `Domain: localhost, User: logged in
`; const result = parseConditionals(html, baseContext); expect(result).toContain("Domain: localhost"); expect(result).toContain("User: logged in"); }); it("should handle mixed block and inline conditionals", () => { const html = `Text with inline conditional.
Block conditional
Status: not production
`; const result = parseConditionals(html, baseContext); expect(result).toContain("Status: not production"); }); });