@@ -2,8 +2,13 @@ import { renderHook, act } from "@testing-library/react-hooks";
22import { useAssetDataFetchers } from "./useAssetDataFetchers" ;
33
44describe ( "useAssetDataFetchers (direct option IDs)" , ( ) => {
5- const assetOptionRecordPayload = ( ids ?: string , description ?: string ) => ( {
5+ const assetOptionRecordPayload = (
6+ ids ?: string ,
7+ description ?: string ,
8+ name ?: string
9+ ) => ( {
610 custom_object_record : {
11+ ...( name !== undefined && { name } ) ,
712 custom_object_fields : {
813 ...( ids !== undefined && { "standard::asset_filter_ids" : ids } ) ,
914 ...( description !== undefined && {
@@ -16,9 +21,11 @@ describe("useAssetDataFetchers (direct option IDs)", () => {
1621 const assetTypeOptionRecordPayload = (
1722 ids ?: string ,
1823 isHidden ?: boolean ,
19- description ?: string
24+ description ?: string ,
25+ name ?: string
2026 ) => ( {
2127 custom_object_record : {
28+ ...( name !== undefined && { name } ) ,
2229 custom_object_fields : {
2330 ...( ids !== undefined && { "standard::asset_type_ids" : ids } ) ,
2431 ...( isHidden !== undefined && { "standard::is_hidden" : isHidden } ) ,
@@ -34,10 +41,11 @@ describe("useAssetDataFetchers (direct option IDs)", () => {
3441 global . fetch = jest . fn ( ) as jest . Mock ;
3542 } ) ;
3643
37- it ( "fetchAssets: returns ids and description when assetOptionId exists" , async ( ) => {
44+ it ( "fetchAssets: returns ids, description, and name when assetOptionId exists" , async ( ) => {
3845 const mockAssetResponse = assetOptionRecordPayload (
3946 "a1,a2,a3" ,
40- "Test description"
47+ "Test description" ,
48+ "Assigned asset"
4149 ) ;
4250
4351 ( global . fetch as jest . Mock ) . mockResolvedValueOnce ( {
@@ -49,7 +57,11 @@ describe("useAssetDataFetchers (direct option IDs)", () => {
4957 ) ;
5058
5159 let response :
52- | { assetIds : string | undefined ; assetDescription : string | undefined }
60+ | {
61+ assetIds : string | undefined ;
62+ assetDescription : string | undefined ;
63+ assetName : string | undefined ;
64+ }
5365 | undefined ;
5466 await act ( async ( ) => {
5567 response = await result . current . fetchAssets ( ) ;
@@ -62,6 +74,7 @@ describe("useAssetDataFetchers (direct option IDs)", () => {
6274 expect ( response ) . toEqual ( {
6375 assetIds : "a1,a2,a3" ,
6476 assetDescription : "Test description" ,
77+ assetName : "Assigned asset" ,
6578 } ) ;
6679 } ) ;
6780
@@ -72,7 +85,11 @@ describe("useAssetDataFetchers (direct option IDs)", () => {
7285 ) ;
7386
7487 let response :
75- | { assetIds : string | undefined ; assetDescription : string | undefined }
88+ | {
89+ assetIds : string | undefined ;
90+ assetDescription : string | undefined ;
91+ assetName : string | undefined ;
92+ }
7693 | undefined ;
7794 await act ( async ( ) => {
7895 response = await result . current . fetchAssets ( ) ;
@@ -99,11 +116,11 @@ describe("useAssetDataFetchers (direct option IDs)", () => {
99116 expect ( response ) . toBeUndefined ( ) ;
100117 } ) ;
101118
102- it ( "fetchAssetTypes: returns object with ids, hidden flag, and description " , async ( ) => {
119+ it ( "fetchAssetTypes: returns object with ids, hidden flag, description, and name " , async ( ) => {
103120 ( global . fetch as jest . Mock ) . mockResolvedValueOnce ( {
104121 json : ( ) =>
105122 Promise . resolve (
106- assetTypeOptionRecordPayload ( "t1,t2" , true , "Type description" )
123+ assetTypeOptionRecordPayload ( "t1,t2" , true , "Type description" , "Asset Type" )
107124 ) ,
108125 } ) ;
109126
@@ -114,6 +131,7 @@ describe("useAssetDataFetchers (direct option IDs)", () => {
114131 assetTypeIds ?: string ;
115132 isHiddenAssetsType ?: boolean ;
116133 assetTypeDescription ?: string ;
134+ assetTypeName ?: string ;
117135 }
118136 | undefined ;
119137
@@ -129,6 +147,7 @@ describe("useAssetDataFetchers (direct option IDs)", () => {
129147 assetTypeIds : "t1,t2" ,
130148 isHiddenAssetsType : true ,
131149 assetTypeDescription : "Type description" ,
150+ assetTypeName : "Asset Type" ,
132151 } ) ;
133152 } ) ;
134153
@@ -143,6 +162,7 @@ describe("useAssetDataFetchers (direct option IDs)", () => {
143162 assetTypeIds ?: string ;
144163 isHiddenAssetsType ?: boolean ;
145164 assetTypeDescription ?: string ;
165+ assetTypeName ?: string ;
146166 }
147167 | undefined ;
148168
@@ -154,7 +174,7 @@ describe("useAssetDataFetchers (direct option IDs)", () => {
154174 expect ( out ) . toBeUndefined ( ) ;
155175 } ) ;
156176
157- it ( "fetchAssetTypes: returns { undefined, undefined, undefined } on error" , async ( ) => {
177+ it ( "fetchAssetTypes: returns { undefined, undefined, undefined, undefined } on error" , async ( ) => {
158178 ( global . fetch as jest . Mock ) . mockRejectedValueOnce ( new Error ( "network" ) ) ;
159179
160180 const { result } = renderHook ( ( ) => useAssetDataFetchers ( "AO-1" , "AT-err" ) ) ;
@@ -164,6 +184,7 @@ describe("useAssetDataFetchers (direct option IDs)", () => {
164184 assetTypeIds ?: string ;
165185 isHiddenAssetsType ?: boolean ;
166186 assetTypeDescription ?: string ;
187+ assetTypeName ?: string ;
167188 }
168189 | undefined ;
169190
@@ -175,6 +196,7 @@ describe("useAssetDataFetchers (direct option IDs)", () => {
175196 assetTypeIds : undefined ,
176197 isHiddenAssetsType : undefined ,
177198 assetTypeDescription : undefined ,
199+ assetTypeName : undefined ,
178200 } ) ;
179201 } ) ;
180202
@@ -185,13 +207,18 @@ describe("useAssetDataFetchers (direct option IDs)", () => {
185207 ) ;
186208
187209 let assets :
188- | { assetIds : string | undefined ; assetDescription : string | undefined }
210+ | {
211+ assetIds : string | undefined ;
212+ assetDescription : string | undefined ;
213+ assetName : string | undefined ;
214+ }
189215 | undefined ;
190216 let assetTypes :
191217 | {
192218 assetTypeIds ?: string ;
193219 isHiddenAssetsType ?: boolean ;
194220 assetTypeDescription ?: string ;
221+ assetTypeName ?: string ;
195222 }
196223 | undefined ;
197224
0 commit comments