import { DocumentLinkContent } 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 DocumentLinkConfig = MockConfig export const DocumentLinkMock = { generate(def: Link, config?: DocumentLinkConfig): DocumentLinkContent { let value: DocumentLinkContent 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 = { __TYPE__: "DocumentLink", id: "mock_document_id", ...(text && { text }), ...(variant && { variant }), } } return DocumentLinkContent.encode(value) }, }