@@ -98,7 +98,7 @@ describe('Tests content types', () => {
9898 expect ( count ) . toEqual ( 2 )
9999 } )
100100
101- test ( 'Test fetching entries of content type' , async ( ) => {
101+ test ( 'Test fetching entries of a content type with default parameters ' , async ( ) => {
102102 const contentTypeServices = createContentTypeService ( {
103103 strapi : fakeStrapi ,
104104 } )
@@ -107,19 +107,128 @@ describe('Tests content types', () => {
107107 contentType : 'api::restaurant.restaurant' ,
108108 } )
109109
110+ expect ( fakeStrapi . entityService . findMany ) . toHaveBeenCalledWith (
111+ 'api::restaurant.restaurant' ,
112+ {
113+ fields : '*' ,
114+ start : 0 ,
115+ limit : 500 ,
116+ filters : { } ,
117+ sort : { } ,
118+ populate : '*' ,
119+ publicationState : 'live' ,
120+ }
121+ )
122+ expect ( fakeStrapi . entityService . findMany ) . toHaveBeenCalledTimes ( 1 )
110123 expect ( count ) . toEqual ( [ { id : 1 } ] )
111124 } )
112125
113- test ( 'Test fetching entries on non existing content type' , async ( ) => {
126+ test ( 'Test fetching entries of a content type with custom parameters ' , async ( ) => {
114127 const contentTypeServices = createContentTypeService ( {
115128 strapi : fakeStrapi ,
116129 } )
117130
118131 const count = await contentTypeServices . getEntries ( {
132+ contentType : 'api::restaurant.restaurant' ,
133+ fields : 'title' ,
134+ start : 1 ,
135+ limit : 2 ,
136+ filters : { where : { title : 'hello' } } ,
137+ sort : 'id' ,
138+ populate : { } ,
139+ publicationState : 'preview' ,
140+ } )
141+
142+ expect ( fakeStrapi . entityService . findMany ) . toHaveBeenCalledWith (
143+ 'api::restaurant.restaurant' ,
144+ {
145+ fields : 'title' ,
146+ start : 1 ,
147+ limit : 2 ,
148+ filters : { where : { title : 'hello' } } ,
149+ sort : 'id' ,
150+ populate : { } ,
151+ publicationState : 'preview' ,
152+ }
153+ )
154+ expect ( fakeStrapi . entityService . findMany ) . toHaveBeenCalledTimes ( 1 )
155+ expect ( count ) . toEqual ( [ { id : 1 } ] )
156+ } )
157+
158+ test ( 'Test fetching entries on non existing content type' , async ( ) => {
159+ const contentTypeServices = createContentTypeService ( {
160+ strapi : fakeStrapi ,
161+ } )
162+
163+ const entry = await contentTypeServices . getEntries ( {
164+ contentType : 'api::test.test' ,
165+ } )
166+
167+ expect ( fakeStrapi . entityService . findMany ) . toHaveBeenCalledTimes ( 0 )
168+ expect ( entry ) . toEqual ( [ ] )
169+ } )
170+
171+ test ( 'Test fetching an entry of a content type with default parameters' , async ( ) => {
172+ const contentTypeServices = createContentTypeService ( {
173+ strapi : fakeStrapi ,
174+ } )
175+
176+ const entry = await contentTypeServices . getEntry ( {
177+ contentType : 'api::restaurant.restaurant' ,
178+ id : 200 ,
179+ } )
180+
181+ expect ( fakeStrapi . entityService . findOne ) . toHaveBeenCalledWith (
182+ 'api::restaurant.restaurant' ,
183+ 200 ,
184+ {
185+ fields : '*' ,
186+ populate : '*' ,
187+ }
188+ )
189+ expect ( fakeStrapi . entityService . findOne ) . toHaveBeenCalledTimes ( 1 )
190+ expect ( entry ) . toEqual ( [ { id : 1 } ] )
191+ } )
192+
193+ test ( 'Test fetching an entry of a content type with custom parameters' , async ( ) => {
194+ const contentTypeServices = createContentTypeService ( {
195+ strapi : fakeStrapi ,
196+ } )
197+
198+ const entry = await contentTypeServices . getEntry ( {
199+ contentType : 'api::restaurant.restaurant' ,
200+ id : 200 ,
201+ fields : [ 'title' ] ,
202+ populate : {
203+ subClass : true ,
204+ } ,
205+ } )
206+
207+ expect ( fakeStrapi . entityService . findOne ) . toHaveBeenCalledWith (
208+ 'api::restaurant.restaurant' ,
209+ 200 ,
210+ {
211+ fields : [ 'title' ] ,
212+ populate : {
213+ subClass : true ,
214+ } ,
215+ }
216+ )
217+ expect ( fakeStrapi . entityService . findOne ) . toHaveBeenCalledTimes ( 1 )
218+ expect ( entry ) . toEqual ( [ { id : 1 } ] )
219+ } )
220+
221+ test ( 'Test fetching an entry on a non existing content type' , async ( ) => {
222+ const contentTypeServices = createContentTypeService ( {
223+ strapi : fakeStrapi ,
224+ } )
225+
226+ const count = await contentTypeServices . getEntry ( {
119227 contentType : 'api::test.test' ,
120228 } )
121229
122- expect ( count ) . toEqual ( [ ] )
230+ expect ( fakeStrapi . entityService . findOne ) . toHaveBeenCalledTimes ( 0 )
231+ expect ( count ) . toEqual ( { } )
123232 } )
124233
125234 test ( 'Test operation in batches on entries' , async ( ) => {
@@ -137,8 +246,6 @@ describe('Tests content types', () => {
137246 } ) ) ,
138247 } )
139248
140- console . log ( entries )
141-
142249 expect ( entries [ 0 ] . id ) . toEqual ( 2 )
143250 expect ( entries [ 0 ] . contentType ) . toEqual ( contentType )
144251 } )
0 commit comments