Replace the old team draft Rule with the adopted CommunityRule Creative Team Rule.

Staging still listed the September draft under the old project name. Seed now
upserts the adopted title, summary, and remade-deck cards, and a data migration
renames the existing row so the public catalog picks it up on deploy.
This commit is contained in:
adilallo committed 2026-11-12 15:40:40 -07:00
1 parent 6b4dda0e19
commit 29a8d2b32b
6 files changed
+397

No files matched your search

+102
View File
@@ -0,0 +1,102 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { RULE_VISIBILITY } from "../../lib/ruleVisibility";
import { TEAM_RULE_DRAFT_TITLE, TEAM_RULE_TITLE } from "../../lib/create/teamRule";
const findFirstMock = vi.fn();
const updateMock = vi.fn();
const createMock = vi.fn();
import { seedTeamRule } from "../../prisma/seed/teamRule";
function prismaStub() {
return {
publishedRule: {
findFirst: findFirstMock,
update: updateMock,
create: createMock,
},
};
}
beforeEach(() => {
findFirstMock.mockReset();
updateMock.mockReset();
createMock.mockReset();
});
describe("seedTeamRule", () => {
it("replaces the old draft row in place", async () => {
findFirstMock
.mockResolvedValueOnce({ id: "draft-1" })
.mockResolvedValueOnce(null);
updateMock.mockResolvedValueOnce({
id: "draft-1",
title: TEAM_RULE_TITLE,
});
const result = await seedTeamRule(prismaStub() as never);
expect(result).toEqual({
action: "updated",
id: "draft-1",
title: TEAM_RULE_TITLE,
});
expect(findFirstMock).toHaveBeenNthCalledWith(1, {
where: { title: TEAM_RULE_DRAFT_TITLE },
orderBy: { createdAt: "asc" },
select: { id: true },
});
expect(updateMock).toHaveBeenCalledWith(
expect.objectContaining({
where: { id: "draft-1" },
data: expect.objectContaining({
title: TEAM_RULE_TITLE,
visibility: RULE_VISIBILITY.public_and_featured,
}),
}),
);
expect(createMock).not.toHaveBeenCalled();
});
it("updates an already-renamed adopted row", async () => {
findFirstMock
.mockResolvedValueOnce(null)
.mockResolvedValueOnce({ id: "adopted-1" });
updateMock.mockResolvedValueOnce({
id: "adopted-1",
title: TEAM_RULE_TITLE,
});
const result = await seedTeamRule(prismaStub() as never);
expect(result.action).toBe("updated");
expect(updateMock).toHaveBeenCalledWith(
expect.objectContaining({ where: { id: "adopted-1" } }),
);
});
it("creates the adopted Rule when neither row exists", async () => {
findFirstMock.mockResolvedValueOnce(null).mockResolvedValueOnce(null);
createMock.mockResolvedValueOnce({
id: "new-1",
title: TEAM_RULE_TITLE,
});
const result = await seedTeamRule(prismaStub() as never);
expect(result).toEqual({
action: "created",
id: "new-1",
title: TEAM_RULE_TITLE,
});
expect(createMock).toHaveBeenCalledWith(
expect.objectContaining({
data: expect.objectContaining({
userId: null,
title: TEAM_RULE_TITLE,
visibility: RULE_VISIBILITY.public_and_featured,
}),
}),
);
});
});