e5d1080fb9
Implements the six previously-unscoped feature ideas plus a mobile layout fix reported via screenshot: - Mobile: Recipes/Collections/Pantry/Meal Plan/Shopping Lists headers now stack and wrap instead of clipping buttons on narrow viewports. - Recipe diff/compare view: word/list diff against any past version, next to Restore in version history. - Shared meal plans & shopping lists: new shoppingListMembers/ mealPlanMembers tables (viewer/editor roles, mirrors collectionMembers), share dialogs, membership-checked routes. - PDF cookbook export: /print/collection/[id] renders a whole collection with page breaks, using the existing print-CSS pattern instead of adding a PDF rendering dependency. - Grocery delivery handoff: shopping lists can copy-as-text (works today) or send to Instacart once INSTACART_API_KEY is configured (stub adapter — real API needs a partner agreement). - Personalized "For You" feed tab: ranks public recipes by tag/ dietary overlap with the user's favorited/highly-rated history. - PWA: added manifest.json + icons on top of the existing service worker so the app is installable; cook-mode pages were already cached for offline use. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
60 lines
2.0 KiB
TypeScript
60 lines
2.0 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
|
|
const { mockPlanFindFirst, mockMemberFindFirst } = vi.hoisted(() => ({
|
|
mockPlanFindFirst: vi.fn(),
|
|
mockMemberFindFirst: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("@epicure/db", () => ({
|
|
db: {
|
|
query: {
|
|
mealPlans: { findFirst: mockPlanFindFirst },
|
|
mealPlanMembers: { findFirst: mockMemberFindFirst },
|
|
},
|
|
},
|
|
mealPlans: { id: "id", userId: "user_id" },
|
|
mealPlanMembers: { mealPlanId: "meal_plan_id", userId: "user_id" },
|
|
eq: vi.fn((a, b) => ({ a, b, op: "eq" })),
|
|
and: vi.fn((...args) => ({ args, op: "and" })),
|
|
}));
|
|
|
|
const { getMealPlanAccessById, canWriteMealPlan } = await import("../meal-plan-access");
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
describe("getMealPlanAccessById", () => {
|
|
it("returns null when the plan doesn't exist", async () => {
|
|
mockPlanFindFirst.mockResolvedValue(undefined);
|
|
expect(await getMealPlanAccessById("plan-1", "user-1")).toBeNull();
|
|
});
|
|
|
|
it("grants owner role to the plan's userId", async () => {
|
|
mockPlanFindFirst.mockResolvedValue({ id: "plan-1", userId: "user-1" });
|
|
const access = await getMealPlanAccessById("plan-1", "user-1");
|
|
expect(access?.role).toBe("owner");
|
|
});
|
|
|
|
it("grants the member's assigned role", async () => {
|
|
mockPlanFindFirst.mockResolvedValue({ id: "plan-1", userId: "user-owner" });
|
|
mockMemberFindFirst.mockResolvedValue({ role: "viewer" });
|
|
const access = await getMealPlanAccessById("plan-1", "user-2");
|
|
expect(access?.role).toBe("viewer");
|
|
});
|
|
|
|
it("returns null when the user is neither owner nor a member", async () => {
|
|
mockPlanFindFirst.mockResolvedValue({ id: "plan-1", userId: "user-owner" });
|
|
mockMemberFindFirst.mockResolvedValue(undefined);
|
|
expect(await getMealPlanAccessById("plan-1", "user-2")).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("canWriteMealPlan", () => {
|
|
it("allows owner and editor, denies viewer", () => {
|
|
expect(canWriteMealPlan("owner")).toBe(true);
|
|
expect(canWriteMealPlan("editor")).toBe(true);
|
|
expect(canWriteMealPlan("viewer")).toBe(false);
|
|
});
|
|
});
|