@@ -113,6 +113,96 @@ describe('Tests content types', () => {
113113 expect ( tasks ) . toEqual ( 10 )
114114 } )
115115
116+
117+ test ( 'Test to add entries linked to multiple indexes in Meilisearch' , async ( ) => {
118+ const pluginMock = jest . fn ( ( ) => ( {
119+ // This rewrites only the needed methods to reach the system under test (removeSensitiveFields)
120+ service : jest . fn ( ) . mockImplementation ( ( ) => {
121+ return {
122+ async actionInBatches ( { contentType = 'restaurant' , callback } ) {
123+ await callback ( {
124+ entries : [
125+ {
126+ id : 1 ,
127+ title : 'title' ,
128+ internal_notes : 'note123' ,
129+ secret : '123' ,
130+ } ,
131+ {
132+ id : 2 ,
133+ title : 'abc' ,
134+ internal_notes : 'note234' ,
135+ secret : '234' ,
136+ } ,
137+ ] ,
138+ contentType,
139+ } )
140+ } ,
141+ getCollectionName : ( { contentType } ) => contentType ,
142+ addIndexedContentType : jest . fn ( ) ,
143+ subscribeContentType : jest . fn ( ) ,
144+ getCredentials : ( ) => ( { } ) ,
145+ }
146+ } ) ,
147+ } ) )
148+
149+ // Spy
150+ const client = new Meilisearch ( { host : 'abc' } )
151+
152+ const meilisearchService = createMeilisearchService ( {
153+ strapi : {
154+ plugin : pluginMock ,
155+ contentTypes : {
156+ restaurant : {
157+ attributes : {
158+ id : { private : false } ,
159+ title : { private : false } ,
160+ internal_notes : { private : true } ,
161+ secret : { private : true } ,
162+ } ,
163+ } ,
164+ } ,
165+ config : {
166+ get : jest . fn ( ( ) => ( {
167+ restaurant : {
168+ noSanitizePrivateFields : [ 'internal_notes' ] ,
169+ indexName : [ 'customIndex' , 'anotherIndex' ] ,
170+ } ,
171+ } ) ) ,
172+ } ,
173+ log : mockLogger ,
174+ } ,
175+ contentTypes : {
176+ restaurant : {
177+ attributes : {
178+ id : { private : false } ,
179+ title : { private : false } ,
180+ internal_notes : { private : true } ,
181+ secret : { private : true } ,
182+ } ,
183+ } ,
184+ } ,
185+ } )
186+
187+ const mockEntry = { attributes : { id : 1 } }
188+ const tasks = await meilisearchService . addEntriesToMeilisearch ( {
189+ contentType : 'restaurant' ,
190+ entries : [ mockEntry , mockEntry ] ,
191+ } )
192+
193+ expect ( strapi . log . info ) . toHaveBeenCalledTimes ( 2 )
194+ expect ( strapi . log . info ) . toHaveBeenCalledWith (
195+ 'The task to add 2 documents to the Meilisearch index "customIndex" has been enqueued (Task uid: undefined).'
196+ )
197+ expect ( strapi . log . info ) . toHaveBeenCalledWith (
198+ 'The task to add 2 documents to the Meilisearch index "anotherIndex" has been enqueued (Task uid: undefined).'
199+ )
200+ expect ( client . index ( '' ) . addDocuments ) . toHaveBeenCalledTimes ( 2 )
201+ expect ( client . index ) . toHaveBeenCalledWith ( 'customIndex' )
202+ expect ( client . index ) . toHaveBeenCalledWith ( 'anotherIndex' )
203+ expect ( tasks ) . toEqual ( 10 )
204+ } )
205+
116206 test ( 'Test to delete entries from Meilisearch' , async ( ) => {
117207 const customStrapi = createStrapiMock ( {
118208 restaurantConfig : {
0 commit comments