@@ -28,6 +28,140 @@ describe("Catalog Operations", () => {
2828 afterEach ( ( ) => {
2929 jest . clearAllMocks ( ) ;
3030 } ) ;
31+
32+ describe ( "createCatalog" , ( ) => {
33+ it ( "should create catalog with correct endpoint" , async ( ) => {
34+ const mockResponse = {
35+ data : {
36+ msg : "Catalog created successfully" ,
37+ code : "Success" ,
38+ } ,
39+ } ;
40+ mockAxiosInstance . post . mockResolvedValue ( mockResponse ) ;
41+
42+ const result = await client . createCatalog ( "test-catalog" ) ;
43+
44+ expect ( mockAxiosInstance . post ) . toHaveBeenCalledWith (
45+ "/api/catalogs/test-catalog"
46+ ) ;
47+ expect ( result ) . toEqual ( mockResponse . data ) ;
48+ } ) ;
49+
50+ it ( "should encode catalog name with special characters" , async ( ) => {
51+ const mockResponse = {
52+ data : {
53+ msg : "Catalog created successfully" ,
54+ code : "Success" ,
55+ } ,
56+ } ;
57+ mockAxiosInstance . post . mockResolvedValue ( mockResponse ) ;
58+
59+ await client . createCatalog ( "test catalog/with+special" ) ;
60+
61+ expect ( mockAxiosInstance . post ) . toHaveBeenCalledWith (
62+ "/api/catalogs/test%20catalog%2Fwith%2Bspecial"
63+ ) ;
64+ } ) ;
65+ } ) ;
66+
67+ describe ( "updateCatalogItems" , ( ) => {
68+ it ( "should encode catalog name with special characters" , async ( ) => {
69+ const mockResponse = {
70+ data : {
71+ msg : "Items updated" ,
72+ code : "Success" ,
73+ } ,
74+ } ;
75+ mockAxiosInstance . post . mockResolvedValue ( mockResponse ) ;
76+
77+ await client . updateCatalogItems ( {
78+ catalogName : "my catalog" ,
79+ items : [ { id : "item1" , name : "Test" } ] ,
80+ } ) ;
81+
82+ expect ( mockAxiosInstance . post ) . toHaveBeenCalledWith (
83+ "/api/catalogs/my%20catalog/items" ,
84+ expect . any ( Object )
85+ ) ;
86+ } ) ;
87+ } ) ;
88+
89+ describe ( "getCatalogItem" , ( ) => {
90+ it ( "should get item with correct endpoint" , async ( ) => {
91+ const mockResponse = {
92+ data : {
93+ catalogName : "products" ,
94+ itemId : "item1" ,
95+ lastModified : 1704067200000 ,
96+ size : 1024 ,
97+ value : { name : "Product 1" } ,
98+ } ,
99+ } ;
100+ mockAxiosInstance . get . mockResolvedValue ( mockResponse ) ;
101+
102+ const result = await client . getCatalogItem ( "products" , "item1" ) ;
103+
104+ expect ( mockAxiosInstance . get ) . toHaveBeenCalledWith (
105+ "/api/catalogs/products/items/item1"
106+ ) ;
107+ expect ( result ) . toEqual ( mockResponse . data ) ;
108+ } ) ;
109+
110+ it ( "should encode catalog name and item ID with special characters" , async ( ) => {
111+ const mockResponse = {
112+ data : {
113+ catalogName : "my catalog" ,
114+ itemId : "item/1" ,
115+ lastModified : 1704067200000 ,
116+ size : 1024 ,
117+ value : { } ,
118+ } ,
119+ } ;
120+ mockAxiosInstance . get . mockResolvedValue ( mockResponse ) ;
121+
122+ await client . getCatalogItem ( "my catalog" , "item/1" ) ;
123+
124+ expect ( mockAxiosInstance . get ) . toHaveBeenCalledWith (
125+ "/api/catalogs/my%20catalog/items/item%2F1"
126+ ) ;
127+ } ) ;
128+ } ) ;
129+
130+ describe ( "deleteCatalogItem" , ( ) => {
131+ it ( "should delete item with correct endpoint" , async ( ) => {
132+ const mockResponse = {
133+ data : {
134+ msg : "Item deleted" ,
135+ code : "Success" ,
136+ } ,
137+ } ;
138+ mockAxiosInstance . delete . mockResolvedValue ( mockResponse ) ;
139+
140+ const result = await client . deleteCatalogItem ( "products" , "item1" ) ;
141+
142+ expect ( mockAxiosInstance . delete ) . toHaveBeenCalledWith (
143+ "/api/catalogs/products/items/item1"
144+ ) ;
145+ expect ( result ) . toEqual ( mockResponse . data ) ;
146+ } ) ;
147+
148+ it ( "should encode catalog name and item ID with special characters" , async ( ) => {
149+ const mockResponse = {
150+ data : {
151+ msg : "Item deleted" ,
152+ code : "Success" ,
153+ } ,
154+ } ;
155+ mockAxiosInstance . delete . mockResolvedValue ( mockResponse ) ;
156+
157+ await client . deleteCatalogItem ( "my catalog" , "item+1" ) ;
158+
159+ expect ( mockAxiosInstance . delete ) . toHaveBeenCalledWith (
160+ "/api/catalogs/my%20catalog/items/item%2B1"
161+ ) ;
162+ } ) ;
163+ } ) ;
164+
31165 describe ( "getCatalogs" , ( ) => {
32166 it ( "should build pagination query parameters" , async ( ) => {
33167 const mockResponse = {
0 commit comments