feat(media): complete mvp1 media foundation workflows
This commit is contained in:
93
packages/db/src/media-foundation.test.ts
Normal file
93
packages/db/src/media-foundation.test.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest"
|
||||
|
||||
const { mockDb } = vi.hoisted(() => ({
|
||||
mockDb: {
|
||||
artworkGallery: { upsert: vi.fn() },
|
||||
artworkAlbum: { upsert: vi.fn() },
|
||||
artworkCategory: { upsert: vi.fn() },
|
||||
artworkTag: { upsert: vi.fn() },
|
||||
artworkRendition: { upsert: vi.fn() },
|
||||
mediaAsset: { create: vi.fn() },
|
||||
artwork: { create: vi.fn() },
|
||||
gallery: { create: vi.fn() },
|
||||
album: { create: vi.fn() },
|
||||
category: { create: vi.fn() },
|
||||
tag: { create: vi.fn() },
|
||||
},
|
||||
}))
|
||||
|
||||
vi.mock("./client", () => ({
|
||||
db: mockDb,
|
||||
}))
|
||||
|
||||
import {
|
||||
attachArtworkRendition,
|
||||
createArtwork,
|
||||
createMediaAsset,
|
||||
linkArtworkToGrouping,
|
||||
} from "./media-foundation"
|
||||
|
||||
describe("media foundation service", () => {
|
||||
beforeEach(() => {
|
||||
for (const value of Object.values(mockDb)) {
|
||||
if ("upsert" in value) {
|
||||
value.upsert.mockReset()
|
||||
}
|
||||
if ("create" in value) {
|
||||
value.create.mockReset()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it("routes grouping links to the correct link table", async () => {
|
||||
mockDb.artworkAlbum.upsert.mockResolvedValue({ id: "link" })
|
||||
|
||||
await linkArtworkToGrouping({
|
||||
artworkId: "f40f4bcc-7148-45d7-a19d-856f7146a47e",
|
||||
groupType: "album",
|
||||
groupId: "f4e094df-0edf-4d5a-8b7b-c51f09cae95e",
|
||||
})
|
||||
|
||||
expect(mockDb.artworkAlbum.upsert).toHaveBeenCalledTimes(1)
|
||||
expect(mockDb.artworkGallery.upsert).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it("upserts rendition by artwork and slot", async () => {
|
||||
mockDb.artworkRendition.upsert.mockResolvedValue({ id: "rendition" })
|
||||
|
||||
await attachArtworkRendition({
|
||||
artworkId: "f40f4bcc-7148-45d7-a19d-856f7146a47e",
|
||||
mediaAssetId: "f4e094df-0edf-4d5a-8b7b-c51f09cae95e",
|
||||
slot: "thumbnail",
|
||||
isPrimary: true,
|
||||
})
|
||||
|
||||
expect(mockDb.artworkRendition.upsert).toHaveBeenCalledTimes(1)
|
||||
expect(mockDb.artworkRendition.upsert.mock.calls[0]?.[0]).toMatchObject({
|
||||
where: {
|
||||
artworkId_slot: {
|
||||
artworkId: "f40f4bcc-7148-45d7-a19d-856f7146a47e",
|
||||
slot: "thumbnail",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it("parses and forwards media and artwork creation payloads", async () => {
|
||||
mockDb.mediaAsset.create.mockResolvedValue({ id: "asset" })
|
||||
mockDb.artwork.create.mockResolvedValue({ id: "artwork" })
|
||||
|
||||
await createMediaAsset({
|
||||
type: "generic",
|
||||
title: "Asset",
|
||||
tags: [],
|
||||
})
|
||||
await createArtwork({
|
||||
title: "Artwork",
|
||||
slug: "artwork",
|
||||
})
|
||||
|
||||
expect(mockDb.mediaAsset.create).toHaveBeenCalledTimes(1)
|
||||
expect(mockDb.artwork.create).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user