import { FileLinkContent, FileLinkType, } from "@prismicio/types-internal/lib/content" import type { Link } from "@prismicio/types-internal/lib/customtypes" import type { MockConfig } from "../../../MockConfig" import { slug } from "../../../utils" export type MediaLinkConfig = MockConfig export const MediaLinkMock = { generate(def: Link, config?: MediaLinkConfig): FileLinkContent { let value: FileLinkContent if (config?.value) { value = config.value } else { const text = def.config?.allowText ? slug() : undefined const variant = def.config?.variants?.[ Math.floor(Math.random() * def.config.variants.length) ] value = config?.value ?? { __TYPE__: FileLinkType, id: "mock_Media_link", kind: "file", name: "mock_name", url: "https://source.unsplash.com/daily", size: "0", ...(text && { text }), ...(variant && { variant }), } } return FileLinkContent.encode(value) }, }