Media is now a complete vertical-feature package mirroring auth/blog structure: entities (models + errors), application (repositories + use-cases), infrastructure (real Payload-backed + mock siblings), interface-adapters (per-use-case controllers), DI (symbols + module + container + bind-production), integrations/api (mediaRouter), factory, contract suite, and feature integration tests. Wired into: - packages/core-api/src/root.ts (added `media: mediaRouter`) - apps/web-next/src/server/bind-production.ts (calls bindProductionMedia) - tsconfig.base.json (added @repo/media/api and ./di/bind-production aliases) 56 new tests in @repo/media (13 test files); core-api router test updated to assert media. procedures. All 26 turbo tasks green. Refactor log: §2, §4.1, §4.2, §5.1, §6.1 Spec: §6.5 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
84 lines
3.3 KiB
TypeScript
84 lines
3.3 KiB
TypeScript
// Feature-level test: exercises the full slice
|
|
// use case factory chain → mock repo
|
|
// Tests the full dependency chain via direct injection (no container rebinding).
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
import { MockMediaRepository } from "../src/infrastructure/repositories/media.repository.mock";
|
|
import { getMediaUseCase } from "../src/application/use-cases/get-media.use-case";
|
|
import { listMediaUseCase } from "../src/application/use-cases/list-media.use-case";
|
|
import { deleteMediaUseCase } from "../src/application/use-cases/delete-media.use-case";
|
|
import { getMediaController } from "../src/interface-adapters/controllers/get-media.controller";
|
|
import { listMediaController } from "../src/interface-adapters/controllers/list-media.controller";
|
|
import { deleteMediaController } from "../src/interface-adapters/controllers/delete-media.controller";
|
|
import { MediaNotFoundError } from "../src/entities/errors/media";
|
|
import { mediaFactory } from "../src/__factories__/media.factory";
|
|
|
|
describe("media feature: end-to-end via direct injection", () => {
|
|
function buildChain() {
|
|
const repo = new MockMediaRepository();
|
|
const getUC = getMediaUseCase(repo);
|
|
const listUC = listMediaUseCase(repo);
|
|
const deleteUC = deleteMediaUseCase(repo);
|
|
const getCtrl = getMediaController(getUC);
|
|
const listCtrl = listMediaController(listUC);
|
|
const deleteCtrl = deleteMediaController(deleteUC);
|
|
return { repo, getCtrl, listCtrl, deleteCtrl };
|
|
}
|
|
|
|
it("listMedia returns empty array initially", async () => {
|
|
const { listCtrl } = buildChain();
|
|
const result = await listCtrl({});
|
|
expect(result).toHaveLength(0);
|
|
});
|
|
|
|
it("stores media and retrieves it by id", async () => {
|
|
const { repo, getCtrl } = buildChain();
|
|
const seed = mediaFactory.build({ id: "feat-1" });
|
|
await repo._store(seed);
|
|
|
|
const result = await getCtrl({ id: "feat-1" });
|
|
expect(result.id).toBe("feat-1");
|
|
expect(result.alt).toBe(seed.alt);
|
|
});
|
|
|
|
it("listMedia returns all stored media", async () => {
|
|
const { repo, listCtrl } = buildChain();
|
|
await repo._store(mediaFactory.build());
|
|
await repo._store(mediaFactory.build());
|
|
await repo._store(mediaFactory.build());
|
|
|
|
const result = await listCtrl({});
|
|
expect(result).toHaveLength(3);
|
|
});
|
|
|
|
it("deleteMedia removes media so it can no longer be retrieved", async () => {
|
|
const { repo, getCtrl, deleteCtrl } = buildChain();
|
|
const seed = mediaFactory.build({ id: "feat-del" });
|
|
await repo._store(seed);
|
|
|
|
await deleteCtrl({ id: "feat-del" });
|
|
|
|
await expect(getCtrl({ id: "feat-del" })).rejects.toThrow(MediaNotFoundError);
|
|
});
|
|
|
|
it("getMediaController throws MediaNotFoundError for missing id", async () => {
|
|
const { getCtrl } = buildChain();
|
|
await expect(getCtrl({ id: "does-not-exist" })).rejects.toBeInstanceOf(MediaNotFoundError);
|
|
});
|
|
|
|
it("deleteMediaController throws MediaNotFoundError for missing id", async () => {
|
|
const { deleteCtrl } = buildChain();
|
|
await expect(deleteCtrl({ id: "does-not-exist" })).rejects.toBeInstanceOf(MediaNotFoundError);
|
|
});
|
|
|
|
it("listMedia with limit respects pagination", async () => {
|
|
const { repo, listCtrl } = buildChain();
|
|
for (let i = 0; i < 5; i++) {
|
|
await repo._store(mediaFactory.build());
|
|
}
|
|
|
|
const result = await listCtrl({ limit: 3 });
|
|
expect(result).toHaveLength(3);
|
|
});
|
|
});
|