feat: migrate setup visibility from boolean to three-tier system
Replace isPublic boolean with visibility enum (private/link/public) across the full stack. Add shares table to schema for future share link support. Update all services, routes, schemas, hooks, components, and tests. Plan: 32-01 (Setup Sharing System - Schema Migration) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,7 @@ async function getOrCreateDb(): Promise<Db> {
|
||||
|
||||
// Truncation order respects foreign keys (children first)
|
||||
const TRUNCATE_TABLES = [
|
||||
"shares",
|
||||
"setup_items",
|
||||
"setups",
|
||||
"thread_candidates",
|
||||
|
||||
@@ -40,7 +40,7 @@ async function insertPublicSetup(
|
||||
) {
|
||||
const [row] = await db
|
||||
.insert(setups)
|
||||
.values({ name, userId, isPublic: true })
|
||||
.values({ name, userId, visibility: "public" })
|
||||
.returning();
|
||||
return row;
|
||||
}
|
||||
@@ -76,7 +76,7 @@ describe("Discovery Routes", () => {
|
||||
// Insert a private setup
|
||||
await db
|
||||
.insert(setups)
|
||||
.values({ name: "Private Setup", userId, isPublic: false });
|
||||
.values({ name: "Private Setup", userId, visibility: "private" });
|
||||
|
||||
const res = await app.request("/api/discovery/setups");
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
@@ -111,8 +111,8 @@ describe("Profile Routes", () => {
|
||||
it("includes only public setups", async () => {
|
||||
// Create public and private setups
|
||||
await db.insert(schema.setups).values([
|
||||
{ name: "Public Setup", userId, isPublic: true },
|
||||
{ name: "Private Setup", userId, isPublic: false },
|
||||
{ name: "Public Setup", userId, visibility: "public" },
|
||||
{ name: "Private Setup", userId, visibility: "private" },
|
||||
]);
|
||||
|
||||
const res = await app.request(`/api/users/${userId}/profile`);
|
||||
@@ -181,7 +181,7 @@ describe("Public Setup Routes", () => {
|
||||
it("returns 200 for public setup without auth", async () => {
|
||||
const [setup] = await db
|
||||
.insert(schema.setups)
|
||||
.values({ name: "My Public Setup", userId, isPublic: true })
|
||||
.values({ name: "My Public Setup", userId, visibility: "public" })
|
||||
.returning();
|
||||
|
||||
const res = await app.request(`/api/setups/${setup.id}/public`);
|
||||
@@ -189,14 +189,14 @@ describe("Public Setup Routes", () => {
|
||||
|
||||
const body = await res.json();
|
||||
expect(body.name).toBe("My Public Setup");
|
||||
expect(body.isPublic).toBe(true);
|
||||
expect(body.visibility).toBe("public");
|
||||
expect(body.items).toBeDefined();
|
||||
});
|
||||
|
||||
it("returns 200 for public setup with items", async () => {
|
||||
const [setup] = await db
|
||||
.insert(schema.setups)
|
||||
.values({ name: "Loaded Setup", userId, isPublic: true })
|
||||
.values({ name: "Loaded Setup", userId, visibility: "public" })
|
||||
.returning();
|
||||
|
||||
const [cat] = await db
|
||||
@@ -231,7 +231,7 @@ describe("Public Setup Routes", () => {
|
||||
it("returns 404 for private setup", async () => {
|
||||
const [setup] = await db
|
||||
.insert(schema.setups)
|
||||
.values({ name: "Private Setup", userId, isPublic: false })
|
||||
.values({ name: "Private Setup", userId, visibility: "private" })
|
||||
.returning();
|
||||
|
||||
const res = await app.request(`/api/setups/${setup.id}/public`);
|
||||
|
||||
@@ -47,7 +47,7 @@ async function insertPublicSetup(
|
||||
) {
|
||||
const [setup] = await db
|
||||
.insert(setups)
|
||||
.values({ name, userId, isPublic: true })
|
||||
.values({ name, userId, visibility: "public" })
|
||||
.returning();
|
||||
for (const itemId of itemIds) {
|
||||
await db.insert(setupItems).values({ setupId: setup.id, itemId });
|
||||
@@ -62,7 +62,7 @@ async function insertPrivateSetup(
|
||||
) {
|
||||
const [setup] = await db
|
||||
.insert(setups)
|
||||
.values({ name, userId, isPublic: false })
|
||||
.values({ name, userId, visibility: "private" })
|
||||
.returning();
|
||||
return setup;
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ describe("Profile Service", () => {
|
||||
// Create one public and one private setup
|
||||
const _pub = await createSetup(db, userId, {
|
||||
name: "Public Setup",
|
||||
isPublic: true,
|
||||
visibility: "public",
|
||||
});
|
||||
const _priv = await createSetup(db, userId, { name: "Private Setup" });
|
||||
|
||||
@@ -91,10 +91,10 @@ describe("Profile Service", () => {
|
||||
});
|
||||
|
||||
describe("getPublicSetupWithItems", () => {
|
||||
it("returns setup with items when isPublic is true", async () => {
|
||||
it("returns setup with items when visibility is public", async () => {
|
||||
const setup = await createSetup(db, userId, {
|
||||
name: "Public Setup",
|
||||
isPublic: true,
|
||||
visibility: "public",
|
||||
});
|
||||
|
||||
// Create an item and add to setup
|
||||
@@ -125,7 +125,7 @@ describe("Profile Service", () => {
|
||||
expect(result!.items[0].name).toBe("Tent");
|
||||
});
|
||||
|
||||
it("returns null when isPublic is false", async () => {
|
||||
it("returns null when visibility is private", async () => {
|
||||
const setup = await createSetup(db, userId, {
|
||||
name: "Private Setup",
|
||||
});
|
||||
@@ -140,7 +140,7 @@ describe("Profile Service", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("Setup Service - isPublic", () => {
|
||||
describe("Setup Service - visibility", () => {
|
||||
let db: Db;
|
||||
let userId: number;
|
||||
|
||||
@@ -150,33 +150,33 @@ describe("Setup Service - isPublic", () => {
|
||||
userId = testData.userId;
|
||||
});
|
||||
|
||||
it("createSetup persists isPublic when true", async () => {
|
||||
it("createSetup persists visibility when public", async () => {
|
||||
const setup = await createSetup(db, userId, {
|
||||
name: "Public",
|
||||
isPublic: true,
|
||||
visibility: "public",
|
||||
});
|
||||
expect(setup.isPublic).toBe(true);
|
||||
expect(setup.visibility).toBe("public");
|
||||
});
|
||||
|
||||
it("createSetup defaults isPublic to false", async () => {
|
||||
it("createSetup defaults visibility to private", async () => {
|
||||
const setup = await createSetup(db, userId, { name: "Private" });
|
||||
expect(setup.isPublic).toBe(false);
|
||||
expect(setup.visibility).toBe("private");
|
||||
});
|
||||
|
||||
it("updateSetup can toggle isPublic", async () => {
|
||||
it("updateSetup can change visibility", async () => {
|
||||
const setup = await createSetup(db, userId, { name: "Test" });
|
||||
expect(setup.isPublic).toBe(false);
|
||||
expect(setup.visibility).toBe("private");
|
||||
|
||||
const updated = await updateSetup(db, userId, setup.id, {
|
||||
name: "Test",
|
||||
isPublic: true,
|
||||
visibility: "public",
|
||||
});
|
||||
expect(updated).not.toBeNull();
|
||||
expect(updated!.isPublic).toBe(true);
|
||||
expect(updated!.visibility).toBe("public");
|
||||
});
|
||||
|
||||
it("getAllSetups includes isPublic in response", async () => {
|
||||
await createSetup(db, userId, { name: "Public", isPublic: true });
|
||||
it("getAllSetups includes visibility in response", async () => {
|
||||
await createSetup(db, userId, { name: "Public", visibility: "public" });
|
||||
await createSetup(db, userId, { name: "Private" });
|
||||
|
||||
const setups = await getAllSetups(db, userId);
|
||||
@@ -184,17 +184,17 @@ describe("Setup Service - isPublic", () => {
|
||||
|
||||
const pub = setups.find((s) => s.name === "Public");
|
||||
const priv = setups.find((s) => s.name === "Private");
|
||||
expect(pub!.isPublic).toBe(true);
|
||||
expect(priv!.isPublic).toBe(false);
|
||||
expect(pub!.visibility).toBe("public");
|
||||
expect(priv!.visibility).toBe("private");
|
||||
});
|
||||
|
||||
it("getSetupWithItems includes isPublic", async () => {
|
||||
it("getSetupWithItems includes visibility", async () => {
|
||||
const setup = await createSetup(db, userId, {
|
||||
name: "Test",
|
||||
isPublic: true,
|
||||
visibility: "public",
|
||||
});
|
||||
const result = await getSetupWithItems(db, userId, setup.id);
|
||||
expect(result).not.toBeNull();
|
||||
expect(result!.isPublic).toBe(true);
|
||||
expect(result!.visibility).toBe("public");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user