feat: standardizer changes
This commit is contained in:
1 parent
8728308fc6
commit
70ebcc9cd5
13 files changed
+147
-119
No files matched your search
@@ -235,7 +235,7 @@ export function buildDocumentDefinition(snapshot: BillingReportSnapshot) {
|
||||
columns: [
|
||||
{
|
||||
image: "logo",
|
||||
width: 120,
|
||||
width: 80,
|
||||
},
|
||||
{
|
||||
width: "*",
|
||||
@@ -297,7 +297,7 @@ export function buildDocumentDefinition(snapshot: BillingReportSnapshot) {
|
||||
// Recipient block
|
||||
{
|
||||
stack: addressLines.map((line) => ({ text: line, style: "recipient" })),
|
||||
margin: [0, 0, 0, 20],
|
||||
margin: [0, 40, 0, 20],
|
||||
},
|
||||
|
||||
// Title
|
||||
|
||||
@@ -92,15 +92,10 @@ function createRepository() {
|
||||
function createService() {
|
||||
const state = createRepository();
|
||||
const immich = {
|
||||
listAlbumsForAsset: vi.fn().mockResolvedValue([
|
||||
{
|
||||
id: albumId,
|
||||
albumName: "Presse 2026",
|
||||
description: null,
|
||||
albumThumbnailAssetId: assetId,
|
||||
assetCount: 1,
|
||||
},
|
||||
]),
|
||||
getAlbum: vi.fn().mockResolvedValue({
|
||||
id: albumId,
|
||||
albumName: "Presse 2026",
|
||||
}),
|
||||
getAsset: vi.fn().mockResolvedValue({
|
||||
id: assetId,
|
||||
type: "IMAGE" as const,
|
||||
@@ -162,7 +157,7 @@ test("canonicalizes every UUID before fingerprinting, lookup, Immich calls, and
|
||||
expect(second).toEqual(first);
|
||||
expect(usages).toHaveLength(1);
|
||||
expect(usages[0]).toMatchObject({ editorialId, assetId, albumId, idempotencyKey });
|
||||
expect(immich.listAlbumsForAsset).toHaveBeenCalledWith(assetId);
|
||||
expect(immich.getAlbum).toHaveBeenCalledWith(albumId);
|
||||
expect(immich.getAsset).toHaveBeenCalledWith(assetId);
|
||||
});
|
||||
|
||||
@@ -231,72 +226,54 @@ test.each([
|
||||
}),
|
||||
).rejects.toMatchObject({ code });
|
||||
expect(findIntent).not.toHaveBeenCalled();
|
||||
expect(immich.listAlbumsForAsset).not.toHaveBeenCalled();
|
||||
expect(immich.getAlbum).not.toHaveBeenCalled();
|
||||
expect(immich.getAsset).not.toHaveBeenCalled();
|
||||
},
|
||||
);
|
||||
|
||||
test("rejects an asset outside the exact requested album", async () => {
|
||||
const { service, immich, usages } = createService();
|
||||
immich.listAlbumsForAsset.mockResolvedValue([
|
||||
{
|
||||
id: otherAlbumId,
|
||||
albumName: "Andere Bilder",
|
||||
description: null,
|
||||
albumThumbnailAssetId: null,
|
||||
assetCount: 1,
|
||||
},
|
||||
]);
|
||||
immich.getAsset.mockResolvedValue({
|
||||
id: assetId,
|
||||
type: "IMAGE",
|
||||
originalFileName: "jubel.jpg",
|
||||
albums: [{ id: otherAlbumId }],
|
||||
});
|
||||
|
||||
await expect(service.createNewUsage(newUsageInput)).rejects.toMatchObject({
|
||||
code: "ASSET_NOT_IN_ALBUM",
|
||||
});
|
||||
expect(immich.getAsset).not.toHaveBeenCalled();
|
||||
expect(immich.getAlbum).not.toHaveBeenCalled();
|
||||
expect(usages).toHaveLength(0);
|
||||
});
|
||||
|
||||
test("rejects removal from the requested album between preflight and locked refresh", async () => {
|
||||
const { service, immich, usages } = createService();
|
||||
immich.listAlbumsForAsset
|
||||
.mockResolvedValueOnce([
|
||||
{
|
||||
id: albumId,
|
||||
albumName: "Presse 2026",
|
||||
description: null,
|
||||
albumThumbnailAssetId: assetId,
|
||||
assetCount: 1,
|
||||
},
|
||||
])
|
||||
.mockResolvedValueOnce([]);
|
||||
const currentAsset = {
|
||||
id: assetId,
|
||||
type: "IMAGE" as const,
|
||||
originalFileName: "jubel.jpg",
|
||||
originalMimeType: "image/jpeg",
|
||||
localDateTime: null,
|
||||
fileCreatedAt: null,
|
||||
albums: [{ id: albumId }],
|
||||
};
|
||||
immich.getAsset
|
||||
.mockResolvedValueOnce(currentAsset)
|
||||
.mockResolvedValueOnce({ ...currentAsset, albums: [] });
|
||||
|
||||
await expect(service.createNewUsage(newUsageInput)).rejects.toMatchObject({
|
||||
code: "ASSET_NOT_IN_ALBUM",
|
||||
});
|
||||
expect(immich.listAlbumsForAsset).toHaveBeenCalledTimes(2);
|
||||
expect(immich.getAsset).toHaveBeenCalledTimes(2);
|
||||
expect(usages).toHaveLength(0);
|
||||
});
|
||||
|
||||
test("persists metadata from the locked final Immich refresh", async () => {
|
||||
const { service, immich, usages } = createService();
|
||||
immich.listAlbumsForAsset
|
||||
.mockResolvedValueOnce([
|
||||
{
|
||||
id: albumId,
|
||||
albumName: "Presse 2026",
|
||||
description: null,
|
||||
albumThumbnailAssetId: assetId,
|
||||
assetCount: 1,
|
||||
},
|
||||
])
|
||||
.mockResolvedValueOnce([
|
||||
{
|
||||
id: albumId,
|
||||
albumName: "Presse final",
|
||||
description: null,
|
||||
albumThumbnailAssetId: assetId,
|
||||
assetCount: 1,
|
||||
},
|
||||
]);
|
||||
immich.getAlbum
|
||||
.mockResolvedValueOnce({ id: albumId, albumName: "Presse 2026" })
|
||||
.mockResolvedValueOnce({ id: albumId, albumName: "Presse final" });
|
||||
const currentAsset = {
|
||||
id: assetId,
|
||||
type: "IMAGE" as const,
|
||||
@@ -317,6 +294,7 @@ test("persists metadata from the locked final Immich refresh", async () => {
|
||||
await service.createNewUsage(newUsageInput);
|
||||
|
||||
expect(immich.getAsset).toHaveBeenCalledTimes(2);
|
||||
expect(immich.getAlbum).toHaveBeenCalledTimes(2);
|
||||
expect(usages).toEqual([
|
||||
expect.objectContaining({ albumName: "Presse final", filename: "final.jpg" }),
|
||||
]);
|
||||
|
||||
@@ -57,11 +57,12 @@ export type UsageRepository = {
|
||||
};
|
||||
|
||||
type UsageImmich = {
|
||||
listAlbumsForAsset(assetId: string): Promise<ImmichAlbumSummary[]>;
|
||||
getAlbum(albumId: string): Promise<{ id: string; albumName: string }>;
|
||||
getAsset(assetId: string): Promise<{
|
||||
id: string;
|
||||
type: string;
|
||||
originalFileName: string;
|
||||
albums?: { id: string }[];
|
||||
}>;
|
||||
};
|
||||
|
||||
@@ -87,16 +88,16 @@ export function createUsageService({
|
||||
const existing = await repository.findIntent(input.editorialId, input.idempotencyKey);
|
||||
if (existing) return resolveIntent(existing, fingerprint, "new_usage");
|
||||
|
||||
const album = await loadRequestedAlbum(immich, input.assetId, input.albumId);
|
||||
const asset = await loadImageAsset(immich, input.assetId);
|
||||
const album = await loadRequestedAlbum(immich, asset, input.albumId);
|
||||
const persisted = await repository.createBillableIntent({
|
||||
...input,
|
||||
albumName: normalizeUpstreamSnapshot(album.albumName),
|
||||
filename: normalizeUpstreamSnapshot(asset.originalFileName),
|
||||
requestFingerprint: fingerprint,
|
||||
}, async () => {
|
||||
const currentAlbum = await loadRequestedAlbum(immich, input.assetId, input.albumId);
|
||||
const currentAsset = await loadImageAsset(immich, input.assetId);
|
||||
const currentAlbum = await loadRequestedAlbum(immich, currentAsset, input.albumId);
|
||||
return {
|
||||
albumName: normalizeUpstreamSnapshot(currentAlbum.albumName),
|
||||
filename: normalizeUpstreamSnapshot(currentAsset.originalFileName),
|
||||
@@ -328,17 +329,18 @@ function normalizeNewUsageInput(input: CreateNewUsageInput): CreateNewUsageInput
|
||||
|
||||
async function loadRequestedAlbum(
|
||||
immich: UsageImmich,
|
||||
assetId: string,
|
||||
asset: Awaited<ReturnType<UsageImmich["getAsset"]>>,
|
||||
albumId: string,
|
||||
): Promise<ImmichAlbumSummary> {
|
||||
let albums: ImmichAlbumSummary[];
|
||||
): Promise<{ id: string; albumName: string }> {
|
||||
if (!asset.albums?.some((a) => a.id === albumId)) {
|
||||
throw new UsageAccountingError("ASSET_NOT_IN_ALBUM");
|
||||
}
|
||||
let album;
|
||||
try {
|
||||
albums = await immich.listAlbumsForAsset(assetId);
|
||||
album = await immich.getAlbum(albumId);
|
||||
} catch {
|
||||
throw new UsageAccountingError("IMMICH_UNAVAILABLE");
|
||||
}
|
||||
const album = albums.find((candidate) => candidate.id === albumId);
|
||||
if (!album) throw new UsageAccountingError("ASSET_NOT_IN_ALBUM");
|
||||
return album;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user