@@ -95,7 +95,8 @@ describe('metadataTaxonomyFetcher', () => {
9595 } ) ;
9696} ) ;
9797
98- describe ( 'metadataNodeTaxonomiesFetcher' , ( ) => {
98+ // TODO: delete whole section during clean up as for now we have to handle both new and old naming convention
99+ describe ( 'metadataTaxonomyNodeAncestorsFetcher (old keys naming convention)' , ( ) => {
99100 const fileID = '12345' ;
100101 const scope = 'global' ;
101102 const taxonomyKey = 'taxonomy_123' ;
@@ -199,6 +200,112 @@ describe('metadataNodeTaxonomiesFetcher', () => {
199200
200201 expect ( result ) . toEqual ( expectedResult ) ;
201202 } ) ;
203+ } ) ;
204+
205+ describe ( 'metadataTaxonomyNodeAncestorsFetcher (new keys naming convention)' , ( ) => {
206+ const fileID = '12345' ;
207+ const scope = 'global' ;
208+ const taxonomyKey = 'taxonomy_123' ;
209+ const nodeID = 'node_abc' ;
210+
211+ let apiMock : jest . Mocked < API > ;
212+
213+ beforeEach ( ( ) => {
214+ apiMock = {
215+ getMetadataAPI : jest . fn ( ) . mockReturnValue ( {
216+ getMetadataTaxonomy : jest . fn ( ) ,
217+ getMetadataTaxonomyNode : jest . fn ( ) ,
218+ } ) ,
219+ } ;
220+ } ) ;
221+
222+ test ( 'should fetch taxonomy and node data and return formatted data' , async ( ) => {
223+ const mockTaxonomy = {
224+ display_name : 'Geography' ,
225+ namespace : 'my_enterprise' ,
226+ id : 'my_id' ,
227+ key : 'geography' ,
228+ levels : [
229+ { level : 1 , display_name : 'Level 1' , description : 'Description 1' } ,
230+ { level : 2 , display_name : 'Level 2' , description : 'Description 2' } ,
231+ { level : 3 , display_name : 'Level 3' , description : 'Description 3' } ,
232+ ] ,
233+ } ;
234+
235+ const mockTaxonomyNode = {
236+ id : 'node_abc' ,
237+ level : 1 ,
238+ display_name : 'Node ABC' ,
239+ ancestors : [ { id : 'ancestor_1' , level : 2 , display_name : 'Ancestor 1' } ] ,
240+ } ;
241+
242+ apiMock . getMetadataAPI ( false ) . getMetadataTaxonomy . mockResolvedValue ( mockTaxonomy ) ;
243+ apiMock . getMetadataAPI ( false ) . getMetadataTaxonomyNode . mockResolvedValue ( mockTaxonomyNode ) ;
244+
245+ const result = await metadataTaxonomyNodeAncestorsFetcher ( apiMock , fileID , scope , taxonomyKey , nodeID ) ;
246+
247+ const expectedResult = [
248+ {
249+ level : 1 ,
250+ levelName : 'Level 1' ,
251+ description : 'Description 1' ,
252+ id : 'node_abc' ,
253+ levelValue : 'Node ABC' ,
254+ } ,
255+ {
256+ level : 2 ,
257+ levelName : 'Level 2' ,
258+ description : 'Description 2' ,
259+ id : 'ancestor_1' ,
260+ levelValue : 'Ancestor 1' ,
261+ } ,
262+ ] ;
263+
264+ expect ( apiMock . getMetadataAPI ) . toHaveBeenCalledWith ( false ) ;
265+ expect ( apiMock . getMetadataAPI ( false ) . getMetadataTaxonomy ) . toHaveBeenCalledWith ( fileID , scope , taxonomyKey ) ;
266+ expect ( apiMock . getMetadataAPI ( false ) . getMetadataTaxonomyNode ) . toHaveBeenCalledWith (
267+ fileID ,
268+ scope ,
269+ taxonomyKey ,
270+ nodeID ,
271+ true ,
272+ ) ;
273+ expect ( result ) . toEqual ( expectedResult ) ;
274+ } ) ;
275+
276+ test ( 'should handle empty ancestors array' , async ( ) => {
277+ const mockTaxonomy = {
278+ display_name : 'Geography' ,
279+ namespace : 'my_enterprise' ,
280+ id : 'my_id' ,
281+ key : 'geography' ,
282+ levels : [ { level : 1 , display_name : 'Level 1' , description : 'Description 1' } ] ,
283+ } ;
284+
285+ const mockTaxonomyNode = {
286+ id : 'node_abc' ,
287+ level : 1 ,
288+ display_name : 'Node ABC' ,
289+ ancestors : [ ] ,
290+ } ;
291+
292+ apiMock . getMetadataAPI ( false ) . getMetadataTaxonomy . mockResolvedValue ( mockTaxonomy ) ;
293+ apiMock . getMetadataAPI ( false ) . getMetadataTaxonomyNode . mockResolvedValue ( mockTaxonomyNode ) ;
294+
295+ const result = await metadataTaxonomyNodeAncestorsFetcher ( apiMock , fileID , scope , taxonomyKey , nodeID ) ;
296+
297+ const expectedResult = [
298+ {
299+ level : 1 ,
300+ levelName : 'Level 1' ,
301+ description : 'Description 1' ,
302+ id : 'node_abc' ,
303+ levelValue : 'Node ABC' ,
304+ } ,
305+ ] ;
306+
307+ expect ( result ) . toEqual ( expectedResult ) ;
308+ } ) ;
202309
203310 test ( 'should throw an error if getMetadataTaxonomy fails' , async ( ) => {
204311 const error = new Error ( 'API Error' ) ;
0 commit comments