97 lines
2.5 KiB
TypeScript
97 lines
2.5 KiB
TypeScript
import { expect, test, vi } from "vitest";
|
|
|
|
import {
|
|
archiveLibraryResource,
|
|
updateLibraryResource,
|
|
} from "@/features/libraries/manage-resource";
|
|
|
|
test("updates resource metadata and cover through the library item route", async () => {
|
|
const fetchMock = vi.fn().mockResolvedValue(
|
|
new Response(
|
|
JSON.stringify({
|
|
data: {
|
|
item: {
|
|
id: "12",
|
|
libraryType: "models",
|
|
name: "Ava Studio Updated",
|
|
description: "新的描述",
|
|
previewUri: "https://images.marcusd.me/library/models/ava/gallery-1.png",
|
|
originalUri: "https://images.marcusd.me/library/models/ava/original.png",
|
|
tags: ["女装", "更新"],
|
|
files: [
|
|
{
|
|
id: 101,
|
|
role: "thumbnail",
|
|
url: "https://images.marcusd.me/library/models/ava/thumb.png",
|
|
},
|
|
{
|
|
id: 102,
|
|
role: "gallery",
|
|
url: "https://images.marcusd.me/library/models/ava/gallery-1.png",
|
|
},
|
|
],
|
|
isMock: false,
|
|
backendId: 12,
|
|
poseId: null,
|
|
},
|
|
},
|
|
}),
|
|
{ status: 200 },
|
|
),
|
|
);
|
|
|
|
const updated = await updateLibraryResource({
|
|
fetchFn: fetchMock,
|
|
libraryType: "models",
|
|
resourceId: "12",
|
|
values: {
|
|
name: "Ava Studio Updated",
|
|
description: "新的描述",
|
|
tags: ["女装", "更新"],
|
|
coverFileId: 102,
|
|
},
|
|
});
|
|
|
|
expect(updated).toMatchObject({
|
|
id: "12",
|
|
name: "Ava Studio Updated",
|
|
previewUri: "https://images.marcusd.me/library/models/ava/gallery-1.png",
|
|
});
|
|
expect(fetchMock).toHaveBeenCalledWith("/api/libraries/models/12", {
|
|
method: "PATCH",
|
|
headers: {
|
|
"content-type": "application/json",
|
|
},
|
|
body: JSON.stringify({
|
|
name: "Ava Studio Updated",
|
|
description: "新的描述",
|
|
tags: ["女装", "更新"],
|
|
coverFileId: 102,
|
|
}),
|
|
});
|
|
});
|
|
|
|
test("archives a resource through the library item route", async () => {
|
|
const fetchMock = vi.fn().mockResolvedValue(
|
|
new Response(
|
|
JSON.stringify({
|
|
data: {
|
|
id: "12",
|
|
},
|
|
}),
|
|
{ status: 200 },
|
|
),
|
|
);
|
|
|
|
const archivedId = await archiveLibraryResource({
|
|
fetchFn: fetchMock,
|
|
libraryType: "models",
|
|
resourceId: "12",
|
|
});
|
|
|
|
expect(archivedId).toBe("12");
|
|
expect(fetchMock).toHaveBeenCalledWith("/api/libraries/models/12", {
|
|
method: "DELETE",
|
|
});
|
|
});
|