@@ -49,6 +49,19 @@ jest.mock('@aws-sdk/lib-storage', () => {
4949 } ;
5050} ) ;
5151
52+ export const expectParents = (
53+ data : { name : string ; id : string ; path : string } [ ] ,
54+ parents : { name : string ; id : string ; path : string } [ ] ,
55+ ) => {
56+ expect ( data ) . toHaveLength ( parents . length ) ;
57+
58+ for ( let i = 0 ; i < parents . length ; i ++ ) {
59+ expect ( data [ i ] . id ) . toEqual ( parents [ i ] . id ) ;
60+ expect ( data [ i ] . name ) . toEqual ( parents [ i ] . name ) ;
61+ expect ( data [ i ] . path ) . toEqual ( parents [ i ] . path ) ;
62+ }
63+ } ;
64+
5265describe ( 'Item routes tests' , ( ) => {
5366 let app : FastifyInstance ;
5467
@@ -1364,63 +1377,19 @@ describe('Item routes tests', () => {
13641377 assertIsMemberForTest ( actor ) ;
13651378 mockAuthenticate ( actor ) ;
13661379
1367- const parents = [ parent , child1 ] . map ( ( i ) =>
1368- new ItemWrapper ( { ...i , creator : null } , { permission : PermissionLevel . Admin } ) . packed ( ) ,
1369- ) ;
1380+ const parents = [ parent , child1 ] ;
13701381
13711382 const response = await app . inject ( {
13721383 method : HttpMethod . Get ,
13731384 url : `/items/${ childOfChild . id } /parents` ,
13741385 } ) ;
13751386
1376- const data = response . json < PackedItem [ ] > ( ) ;
1377- expect ( data ) . toHaveLength ( parents . length ) ;
1378- data . forEach ( ( p , idx ) => {
1379- expectPackedItem ( p , parents [ idx ] ) ;
1380- expectThumbnails ( p , MOCK_SIGNED_URL , false ) ;
1381- } ) ;
1382- expect ( response . statusCode ) . toBe ( StatusCodes . OK ) ;
1383- } ) ;
1384-
1385- it ( 'Returns successfully with thumbnails' , async ( ) => {
1386- const {
1387- actor,
1388- items : [ parent , child1 , childOfChild ] ,
1389- } = await seedFromJson ( {
1390- items : [
1391- {
1392- settings : { hasThumbnail : true } ,
1393- memberships : [ { account : 'actor' , permission : PermissionLevel . Admin } ] ,
1394- children : [
1395- {
1396- settings : { hasThumbnail : true } ,
1397- children : [ { settings : { hasThumbnail : true } } ] ,
1398- } ,
1399- ] ,
1400- } ,
1401- { } ,
1402- ] ,
1403- } ) ;
1404- assertIsDefined ( actor ) ;
1405- assertIsMemberForTest ( actor ) ;
1406- mockAuthenticate ( actor ) ;
1407-
1408- const response = await app . inject ( {
1409- method : HttpMethod . Get ,
1410- url : `/items/${ childOfChild . id } /parents` ,
1411- } ) ;
1387+ const data = response . json ( ) ;
14121388
1413- const parents = [ parent , child1 ] . map ( ( i ) =>
1414- new ItemWrapper ( { ...i , creator : null } , { permission : PermissionLevel . Admin } ) . packed ( ) ,
1415- ) ;
1416- const data = response . json < PackedItem [ ] > ( ) ;
1417- expect ( data ) . toHaveLength ( parents . length ) ;
1418- data . forEach ( ( p , idx ) => {
1419- expectPackedItem ( p , parents [ idx ] ) ;
1420- expectThumbnails ( p , MOCK_SIGNED_URL , true ) ;
1421- } ) ;
1389+ expectParents ( data , parents ) ;
14221390 expect ( response . statusCode ) . toBe ( StatusCodes . OK ) ;
14231391 } ) ;
1392+
14241393 it ( 'Bad Request for invalid id' , async ( ) => {
14251394 const response = await app . inject ( {
14261395 method : HttpMethod . Get ,
@@ -1465,7 +1434,6 @@ describe('Item routes tests', () => {
14651434 it ( 'Returns successfully' , async ( ) => {
14661435 const {
14671436 items : [ parent , child1 , childOfChild ] ,
1468- itemVisibilities : [ publicVisibility ] ,
14691437 } = await seedFromJson ( {
14701438 actor : null ,
14711439 items : [
@@ -1486,11 +1454,7 @@ describe('Item routes tests', () => {
14861454
14871455 const data = response . json ( ) ;
14881456 expect ( data ) . toHaveLength ( parents . length ) ;
1489- data . forEach ( ( p , idx ) => {
1490- expectPackedItem ( p , { ...parents [ idx ] , permission : null } , undefined , undefined , [
1491- publicVisibility ,
1492- ] ) ;
1493- } ) ;
1457+ expectParents ( data , parents ) ;
14941458 expect ( response . statusCode ) . toBe ( StatusCodes . OK ) ;
14951459 } ) ;
14961460 } ) ;
0 commit comments