@@ -20,7 +20,7 @@ describe('getAllContentIds', () => {
2020 ctx . status ( 200 ) ,
2121 ctx . json ( {
2222 totalCount : 100 ,
23- } )
23+ } ) ,
2424 ) ;
2525 } ) ,
2626 rest . get ( `${ testBaseUrl } /getAllContentIds-list-type` , ( _ , res , ctx ) => {
@@ -30,9 +30,9 @@ describe('getAllContentIds', () => {
3030 contents : Array ( 100 )
3131 . fill ( null )
3232 . map ( ( _ , index ) => ( { id : `id${ index } ` } ) ) ,
33- } )
33+ } ) ,
3434 ) ;
35- } )
35+ } ) ,
3636 ) ;
3737
3838 const result = await client . getAllContentIds ( {
@@ -51,7 +51,7 @@ describe('getAllContentIds', () => {
5151 ctx . status ( 200 ) ,
5252 ctx . json ( {
5353 totalCount : 250 ,
54- } )
54+ } ) ,
5555 ) ;
5656 } ) ,
5757 rest . get ( `${ testBaseUrl } /getAllContentIds-list-type` , ( _ , res , ctx ) => {
@@ -61,7 +61,7 @@ describe('getAllContentIds', () => {
6161 contents : Array ( 100 )
6262 . fill ( null )
6363 . map ( ( _ , index ) => ( { id : `id${ index } ` } ) ) ,
64- } )
64+ } ) ,
6565 ) ;
6666 } ) ,
6767 rest . get ( `${ testBaseUrl } /getAllContentIds-list-type` , ( _ , res , ctx ) => {
@@ -71,7 +71,7 @@ describe('getAllContentIds', () => {
7171 contents : Array ( 100 )
7272 . fill ( null )
7373 . map ( ( _ , index ) => ( { id : `id${ index + 100 } ` } ) ) ,
74- } )
74+ } ) ,
7575 ) ;
7676 } ) ,
7777 rest . get ( `${ testBaseUrl } /getAllContentIds-list-type` , ( _ , res , ctx ) => {
@@ -81,9 +81,9 @@ describe('getAllContentIds', () => {
8181 contents : Array ( 50 )
8282 . fill ( null )
8383 . map ( ( _ , index ) => ( { id : `id${ index + 200 } ` } ) ) ,
84- } )
84+ } ) ,
8585 ) ;
86- } )
86+ } ) ,
8787 ) ;
8888
8989 const result = await client . getAllContentIds ( {
@@ -94,4 +94,68 @@ describe('getAllContentIds', () => {
9494 expect ( result ) . toContain ( 'id0' ) ;
9595 expect ( result ) . toContain ( 'id249' ) ;
9696 } ) ;
97+
98+ test ( 'should fetch all content ids with target field' , async ( ) => {
99+ server . use (
100+ rest . get ( `${ testBaseUrl } /getAllContentIds-list-type` , ( _ , res , ctx ) => {
101+ return res . once (
102+ ctx . status ( 200 ) ,
103+ ctx . json ( {
104+ totalCount : 100 ,
105+ } ) ,
106+ ) ;
107+ } ) ,
108+ rest . get ( `${ testBaseUrl } /getAllContentIds-list-type` , ( _ , res , ctx ) => {
109+ return res . once (
110+ ctx . status ( 200 ) ,
111+ ctx . json ( {
112+ contents : Array ( 100 )
113+ . fill ( null )
114+ . map ( ( _ , index ) => ( { url : `id${ index } ` } ) ) ,
115+ } ) ,
116+ ) ;
117+ } ) ,
118+ ) ;
119+
120+ const result = await client . getAllContentIds ( {
121+ endpoint : 'getAllContentIds-list-type' ,
122+ target : 'url' ,
123+ } ) ;
124+
125+ expect ( result ) . toHaveLength ( 100 ) ;
126+ expect ( result ) . toContain ( 'id0' ) ;
127+ expect ( result ) . toContain ( 'id99' ) ;
128+ } ) ;
129+
130+ test ( 'should throw error when target field is not string' , async ( ) => {
131+ server . use (
132+ rest . get ( `${ testBaseUrl } /getAllContentIds-list-type` , ( _ , res , ctx ) => {
133+ return res . once (
134+ ctx . status ( 200 ) ,
135+ ctx . json ( {
136+ totalCount : 100 ,
137+ } ) ,
138+ ) ;
139+ } ) ,
140+ rest . get ( `${ testBaseUrl } /getAllContentIds-list-type` , ( _ , res , ctx ) => {
141+ return res . once (
142+ ctx . status ( 200 ) ,
143+ ctx . json ( {
144+ contents : Array ( 100 )
145+ . fill ( null )
146+ . map ( ( ) => ( { image : { url : 'url' , width : 100 , height : 100 } } ) ) ,
147+ } ) ,
148+ ) ;
149+ } ) ,
150+ ) ;
151+
152+ expect ( ( ) =>
153+ client . getAllContentIds ( {
154+ endpoint : 'getAllContentIds-list-type' ,
155+ target : 'image' ,
156+ } ) ,
157+ ) . toThrowError (
158+ 'The value of the field specified by `target` is not a string.' ,
159+ ) ;
160+ } ) ;
97161} ) ;
0 commit comments