|
| 1 | +import { it, describe, expect } from "vitest"; |
| 2 | + |
| 3 | +import { TEST_HUB_URL, TEST_ACCESS_TOKEN, TEST_USER } from "../test/consts"; |
| 4 | +import { addCollectionItem } from "./add-collection-item"; |
| 5 | +import { listCollections } from "./list-collections"; |
| 6 | +import { collectionInfo } from "./collection-info"; |
| 7 | +import { deleteCollectionItem } from "./delete-collection-item"; |
| 8 | + |
| 9 | +describe("addCollectionItem", () => { |
| 10 | + it("should add a item to a collection", async () => { |
| 11 | + let slug: string = ""; |
| 12 | + let itemId: string = ""; |
| 13 | + |
| 14 | + try { |
| 15 | + for await (const entry of listCollections({ |
| 16 | + search: { owner: [TEST_USER] }, |
| 17 | + limit: 1, |
| 18 | + hubUrl: TEST_HUB_URL, |
| 19 | + })) { |
| 20 | + slug = entry.slug; |
| 21 | + break; |
| 22 | + } |
| 23 | + |
| 24 | + await addCollectionItem({ |
| 25 | + slug, |
| 26 | + item: { |
| 27 | + type: "model", |
| 28 | + id: "quanghuynt14/TestAddCollectionItem", |
| 29 | + }, |
| 30 | + note: "This is a test item", |
| 31 | + accessToken: TEST_ACCESS_TOKEN, |
| 32 | + hubUrl: TEST_HUB_URL, |
| 33 | + }); |
| 34 | + |
| 35 | + const collection = await collectionInfo({ |
| 36 | + slug, |
| 37 | + accessToken: TEST_ACCESS_TOKEN, |
| 38 | + hubUrl: TEST_HUB_URL, |
| 39 | + }); |
| 40 | + |
| 41 | + const item = collection.items.find((item) => item.id === "quanghuynt14/TestAddCollectionItem"); |
| 42 | + |
| 43 | + expect(item).toBeDefined(); |
| 44 | + |
| 45 | + itemId = item?._id || ""; |
| 46 | + } finally { |
| 47 | + await deleteCollectionItem({ |
| 48 | + slug, |
| 49 | + itemId, |
| 50 | + accessToken: TEST_ACCESS_TOKEN, |
| 51 | + hubUrl: TEST_HUB_URL, |
| 52 | + }); |
| 53 | + } |
| 54 | + }); |
| 55 | +}); |
0 commit comments