feat: connect resource library workflows
This commit is contained in:
96
tests/features/libraries/manage-resource.test.ts
Normal file
96
tests/features/libraries/manage-resource.test.ts
Normal file
@@ -0,0 +1,96 @@
|
||||
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",
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user