feat(media): complete mvp1 media foundation workflows
This commit is contained in:
51
packages/content/src/media.test.ts
Normal file
51
packages/content/src/media.test.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
import {
|
||||
attachArtworkRenditionInputSchema,
|
||||
createGroupingInputSchema,
|
||||
createMediaAssetInputSchema,
|
||||
linkArtworkGroupingInputSchema,
|
||||
} from "./media"
|
||||
|
||||
describe("media schemas", () => {
|
||||
it("accepts supported media asset type payload", () => {
|
||||
const parsed = createMediaAssetInputSchema.parse({
|
||||
type: "artwork",
|
||||
title: "Artwork",
|
||||
tags: ["tag-a"],
|
||||
})
|
||||
|
||||
expect(parsed.type).toBe("artwork")
|
||||
expect(parsed.tags).toEqual(["tag-a"])
|
||||
})
|
||||
|
||||
it("validates grouping link payload", () => {
|
||||
const parsed = linkArtworkGroupingInputSchema.parse({
|
||||
artworkId: "f40f4bcc-7148-45d7-a19d-856f7146a47e",
|
||||
groupType: "gallery",
|
||||
groupId: "f4e094df-0edf-4d5a-8b7b-c51f09cae95e",
|
||||
})
|
||||
|
||||
expect(parsed.groupType).toBe("gallery")
|
||||
})
|
||||
|
||||
it("enforces rendition slot enum", () => {
|
||||
const parsed = attachArtworkRenditionInputSchema.parse({
|
||||
artworkId: "f40f4bcc-7148-45d7-a19d-856f7146a47e",
|
||||
mediaAssetId: "f4e094df-0edf-4d5a-8b7b-c51f09cae95e",
|
||||
slot: "thumbnail",
|
||||
})
|
||||
|
||||
expect(parsed.slot).toBe("thumbnail")
|
||||
})
|
||||
|
||||
it("supports grouping defaults", () => {
|
||||
const parsed = createGroupingInputSchema.parse({
|
||||
name: "Featured",
|
||||
slug: "featured",
|
||||
})
|
||||
|
||||
expect(parsed.sortOrder).toBe(0)
|
||||
expect(parsed.isVisible).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -33,7 +33,33 @@ export const createArtworkInputSchema = z.object({
|
||||
availability: z.string().max(180).optional(),
|
||||
})
|
||||
|
||||
export const createGroupingInputSchema = z.object({
|
||||
name: z.string().min(1).max(180),
|
||||
slug: z.string().min(1).max(180),
|
||||
description: z.string().max(5000).optional(),
|
||||
sortOrder: z.number().int().min(0).default(0),
|
||||
isVisible: z.boolean().default(true),
|
||||
})
|
||||
|
||||
export const linkArtworkGroupingInputSchema = z.object({
|
||||
artworkId: z.string().uuid(),
|
||||
groupType: z.enum(["gallery", "album", "category", "tag"]),
|
||||
groupId: z.string().uuid(),
|
||||
})
|
||||
|
||||
export const attachArtworkRenditionInputSchema = z.object({
|
||||
artworkId: z.string().uuid(),
|
||||
mediaAssetId: z.string().uuid(),
|
||||
slot: artworkRenditionSlotSchema,
|
||||
width: z.number().int().positive().optional(),
|
||||
height: z.number().int().positive().optional(),
|
||||
isPrimary: z.boolean().default(false),
|
||||
})
|
||||
|
||||
export type MediaAssetType = z.infer<typeof mediaAssetTypeSchema>
|
||||
export type ArtworkRenditionSlot = z.infer<typeof artworkRenditionSlotSchema>
|
||||
export type CreateMediaAssetInput = z.infer<typeof createMediaAssetInputSchema>
|
||||
export type CreateArtworkInput = z.infer<typeof createArtworkInputSchema>
|
||||
export type CreateGroupingInput = z.infer<typeof createGroupingInputSchema>
|
||||
export type LinkArtworkGroupingInput = z.infer<typeof linkArtworkGroupingInputSchema>
|
||||
export type AttachArtworkRenditionInput = z.infer<typeof attachArtworkRenditionInputSchema>
|
||||
|
||||
Reference in New Issue
Block a user