fanfic-models.test.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { describe, it, expect } from "vitest";
  2. import { BookConfigSchema } from "../models/book.js";
  3. import { BookRulesSchema } from "../models/book-rules.js";
  4. describe("BookConfig fanfic fields", () => {
  5. const base = {
  6. id: "test",
  7. title: "Test",
  8. platform: "other",
  9. genre: "other",
  10. status: "outlining",
  11. createdAt: "2026-01-01T00:00:00.000Z",
  12. updatedAt: "2026-01-01T00:00:00.000Z",
  13. };
  14. it("accepts fanficMode", () => {
  15. const config = BookConfigSchema.parse({ ...base, fanficMode: "canon" });
  16. expect(config.fanficMode).toBe("canon");
  17. });
  18. it("accepts all 4 fanfic modes", () => {
  19. for (const mode of ["canon", "au", "ooc", "cp"]) {
  20. const config = BookConfigSchema.parse({ ...base, fanficMode: mode });
  21. expect(config.fanficMode).toBe(mode);
  22. }
  23. });
  24. it("accepts parentBookId", () => {
  25. const config = BookConfigSchema.parse({ ...base, parentBookId: "parent-book" });
  26. expect(config.parentBookId).toBe("parent-book");
  27. });
  28. it("parses without fanfic fields (backward compatible)", () => {
  29. const config = BookConfigSchema.parse(base);
  30. expect(config.fanficMode).toBeUndefined();
  31. expect(config.parentBookId).toBeUndefined();
  32. });
  33. it("rejects invalid fanfic mode", () => {
  34. expect(() => BookConfigSchema.parse({ ...base, fanficMode: "invalid" })).toThrow();
  35. });
  36. });
  37. describe("BookRules fanfic fields", () => {
  38. it("accepts fanficMode and allowedDeviations", () => {
  39. const rules = BookRulesSchema.parse({
  40. fanficMode: "au",
  41. allowedDeviations: ["magic system changed", "timeline shifted"],
  42. });
  43. expect(rules.fanficMode).toBe("au");
  44. expect(rules.allowedDeviations).toEqual(["magic system changed", "timeline shifted"]);
  45. });
  46. it("defaults allowedDeviations to empty array", () => {
  47. const rules = BookRulesSchema.parse({});
  48. expect(rules.allowedDeviations).toEqual([]);
  49. expect(rules.fanficMode).toBeUndefined();
  50. });
  51. it("parses without fanfic fields (backward compatible)", () => {
  52. const rules = BookRulesSchema.parse({
  53. version: "1.0",
  54. prohibitions: ["test"],
  55. });
  56. expect(rules.fanficMode).toBeUndefined();
  57. expect(rules.allowedDeviations).toEqual([]);
  58. expect(rules.prohibitions).toEqual(["test"]);
  59. });
  60. });