Move four DDD tensions on the Feed aggregate to ground: - #1 The aggregate now holds a domain FeedState (camelCase) instead of the snake_case FeedConfig DTO; infrastructure/feed-mapper.ts owns the FeedState<->FeedConfig/FeedListItem translation as the sole snake_case site outside the HTTP edge. - #3 Replace the edit() recomputeExpiry control flag with a Lifetime VO: passing a lifetime recomputes expiry, omitting it preserves the current one (the dashboard quick-edit path). - #4 Domain events carry their own feedId; dispatchFeedEvents centralizes the drain+dispatch in the application layer (no more manual pullEvents at call sites), keeping infra->application dependency direction intact. - #6 Rename FeedId.fromTrusted to FeedId.unchecked to make the absence of revalidation explicit. Adds Lifetime + feed-mapper round-trip tests. 353 tests green, tsc clean, wrangler dry-run OK. Docs (CLAUDE.md) synced. Co-Authored-By: Claude Opus 4.7 <[email protected]>
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { fromConfigDTO, toConfigDTO, toListItemDTO } from "./feed-mapper";
|
|
import { FeedId } from "../domain/value-objects/feed-id";
|
|
import type { FeedConfig } from "../types";
|
|
|
|
const fullConfig: FeedConfig = {
|
|
title: "News",
|
|
description: "desc",
|
|
language: "en",
|
|
author: "Jane",
|
|
allowed_senders: ["[email protected]"],
|
|
blocked_senders: ["[email protected]"],
|
|
created_at: 1000,
|
|
updated_at: 2000,
|
|
expires_at: 3000,
|
|
};
|
|
|
|
describe("feed-mapper", () => {
|
|
it("round-trips a full config DTO through domain state unchanged", () => {
|
|
expect(toConfigDTO(fromConfigDTO(fullConfig))).toEqual(fullConfig);
|
|
});
|
|
|
|
it("defaults absent sender lists to empty arrays on the domain side", () => {
|
|
const state = fromConfigDTO({
|
|
title: "T",
|
|
language: "en",
|
|
created_at: 1,
|
|
});
|
|
expect(state.allowedSenders).toEqual([]);
|
|
expect(state.blockedSenders).toEqual([]);
|
|
});
|
|
|
|
it("projects the feeds:list item from domain state", () => {
|
|
const item = toListItemDTO(
|
|
FeedId.unchecked("a.b.42"),
|
|
fromConfigDTO(fullConfig),
|
|
);
|
|
expect(item).toEqual({
|
|
id: "a.b.42",
|
|
title: "News",
|
|
description: "desc",
|
|
expires_at: 3000,
|
|
});
|
|
});
|
|
});
|