@@ -2,54 +2,83 @@ import { it, describe, expect } from "vitest";
22
33import { TEST_HUB_URL , TEST_ACCESS_TOKEN , TEST_USER } from "../test/consts" ;
44import { addCollectionItem } from "./add-collection-item" ;
5- import { listCollections } from "./list-collections" ;
65import { collectionInfo } from "./collection-info" ;
76import { deleteCollectionItem } from "./delete-collection-item" ;
7+ import { createCollection } from "./create-collection" ;
8+ import { deleteCollection } from "./delete-collection" ;
89
910describe ( "addCollectionItem" , ( ) => {
1011 it ( "should add a item to a collection" , async ( ) => {
1112 let slug : string = "" ;
12- let itemId : string = "" ;
13+
14+ const randomString = crypto . randomUUID ( ) ;
15+ const title = `Test Collection ${ randomString } ` ;
1316
1417 try {
15- for await ( const entry of listCollections ( {
16- search : { owner : [ TEST_USER ] } ,
17- limit : 1 ,
18+ const result = await createCollection ( {
19+ collection : {
20+ title,
21+ namespace : TEST_USER ,
22+ description : "This is a test collection" ,
23+ private : false ,
24+ } ,
25+ accessToken : TEST_ACCESS_TOKEN ,
1826 hubUrl : TEST_HUB_URL ,
19- } ) ) {
20- slug = entry . slug ;
21- break ;
22- }
27+ } ) ;
28+
29+ slug = result . slug ;
30+
31+ expect ( result . slug . startsWith ( `${ TEST_USER } /test-collection-${ randomString } ` ) ) . toBe ( true ) ;
2332
2433 await addCollectionItem ( {
34+ accessToken : TEST_ACCESS_TOKEN ,
35+ hubUrl : TEST_HUB_URL ,
2536 slug,
2637 item : {
27- type : "model" ,
28- id : "quanghuynt14/TestAddCollectionItem" ,
38+ type : "collection" ,
39+ // temporary, later the slug should work on its own
40+ id : result . slug . slice ( - 24 ) ,
2941 } ,
3042 note : "This is a test item" ,
31- accessToken : TEST_ACCESS_TOKEN ,
32- hubUrl : TEST_HUB_URL ,
3343 } ) ;
3444
35- const collection = await collectionInfo ( {
45+ const items = await collectionInfo ( {
3646 slug,
3747 accessToken : TEST_ACCESS_TOKEN ,
3848 hubUrl : TEST_HUB_URL ,
3949 } ) ;
4050
41- const item = collection . items . find ( ( item ) => item . id === "quanghuynt14/TestAddCollectionItem" ) ;
42-
43- expect ( item ) . toBeDefined ( ) ;
51+ expect ( items . items . length ) . toBe ( 1 ) ;
52+ expect ( items . items [ 0 ] . type ) . toBe ( "collection" ) ;
53+ // temporary, later the slug should work on its own right?
54+ expect ( items . items [ 0 ] . id ) . toBe ( result . slug . slice ( - 24 ) ) ;
55+ expect ( items . items [ 0 ] . note ) . toEqual ( {
56+ html : "This is a test item" ,
57+ text : "This is a test item" ,
58+ } ) ;
4459
45- itemId = item ?. _id || "" ;
46- } finally {
4760 await deleteCollectionItem ( {
4861 slug,
49- itemId,
62+ itemId : items . items [ 0 ] . _id ,
5063 accessToken : TEST_ACCESS_TOKEN ,
5164 hubUrl : TEST_HUB_URL ,
5265 } ) ;
66+
67+ const items2 = await collectionInfo ( {
68+ slug,
69+ accessToken : TEST_ACCESS_TOKEN ,
70+ hubUrl : TEST_HUB_URL ,
71+ } ) ;
72+
73+ expect ( items2 . items . length ) . toBe ( 0 ) ;
74+ } finally {
75+ if ( slug ) {
76+ await deleteCollection ( {
77+ slug,
78+ accessToken : TEST_ACCESS_TOKEN ,
79+ hubUrl : TEST_HUB_URL ,
80+ } ) ;
81+ }
5382 }
5483 } ) ;
5584} ) ;
0 commit comments