@@ -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,16 @@ 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 (
124+ "t1,t2" ,
125+ true ,
126+ "Type description" ,
127+ "Asset Type"
128+ )
107129 ) ,
108130 } ) ;
109131
@@ -114,6 +136,7 @@ describe("useAssetDataFetchers (direct option IDs)", () => {
114136 assetTypeIds ?: string ;
115137 isHiddenAssetsType ?: boolean ;
116138 assetTypeDescription ?: string ;
139+ assetTypeName ?: string ;
117140 }
118141 | undefined ;
119142
@@ -129,6 +152,7 @@ describe("useAssetDataFetchers (direct option IDs)", () => {
129152 assetTypeIds : "t1,t2" ,
130153 isHiddenAssetsType : true ,
131154 assetTypeDescription : "Type description" ,
155+ assetTypeName : "Asset Type" ,
132156 } ) ;
133157 } ) ;
134158
@@ -143,6 +167,7 @@ describe("useAssetDataFetchers (direct option IDs)", () => {
143167 assetTypeIds ?: string ;
144168 isHiddenAssetsType ?: boolean ;
145169 assetTypeDescription ?: string ;
170+ assetTypeName ?: string ;
146171 }
147172 | undefined ;
148173
@@ -154,7 +179,7 @@ describe("useAssetDataFetchers (direct option IDs)", () => {
154179 expect ( out ) . toBeUndefined ( ) ;
155180 } ) ;
156181
157- it ( "fetchAssetTypes: returns { undefined, undefined, undefined } on error" , async ( ) => {
182+ it ( "fetchAssetTypes: returns { undefined, undefined, undefined, undefined } on error" , async ( ) => {
158183 ( global . fetch as jest . Mock ) . mockRejectedValueOnce ( new Error ( "network" ) ) ;
159184
160185 const { result } = renderHook ( ( ) => useAssetDataFetchers ( "AO-1" , "AT-err" ) ) ;
@@ -164,6 +189,7 @@ describe("useAssetDataFetchers (direct option IDs)", () => {
164189 assetTypeIds ?: string ;
165190 isHiddenAssetsType ?: boolean ;
166191 assetTypeDescription ?: string ;
192+ assetTypeName ?: string ;
167193 }
168194 | undefined ;
169195
@@ -175,6 +201,7 @@ describe("useAssetDataFetchers (direct option IDs)", () => {
175201 assetTypeIds : undefined ,
176202 isHiddenAssetsType : undefined ,
177203 assetTypeDescription : undefined ,
204+ assetTypeName : undefined ,
178205 } ) ;
179206 } ) ;
180207
@@ -185,13 +212,18 @@ describe("useAssetDataFetchers (direct option IDs)", () => {
185212 ) ;
186213
187214 let assets :
188- | { assetIds : string | undefined ; assetDescription : string | undefined }
215+ | {
216+ assetIds : string | undefined ;
217+ assetDescription : string | undefined ;
218+ assetName : string | undefined ;
219+ }
189220 | undefined ;
190221 let assetTypes :
191222 | {
192223 assetTypeIds ?: string ;
193224 isHiddenAssetsType ?: boolean ;
194225 assetTypeDescription ?: string ;
226+ assetTypeName ?: string ;
195227 }
196228 | undefined ;
197229
0 commit comments