@@ -2,16 +2,16 @@ import { searchClient, dataset, Movies } from './assets/utils'
22
33describe ( 'Instant MeiliSearch Browser test' , ( ) => {
44 beforeAll ( async ( ) => {
5- try {
6- await searchClient . MeiliSearchClient . deleteIndex ( 'movies' )
7- } catch ( e ) {
8- // movies does not exist
9- }
10- const moviesUpdate = await searchClient . MeiliSearchClient . index (
5+ const deleteTask = await searchClient . MeiliSearchClient . deleteIndex (
6+ 'movies'
7+ )
8+ await searchClient . MeiliSearchClient . waitForTask ( deleteTask . uid )
9+
10+ const documentsTask = await searchClient . MeiliSearchClient . index (
1111 'movies'
1212 ) . addDocuments ( dataset )
13- await searchClient . MeiliSearchClient . index ( 'movies' ) . waitForPendingUpdate (
14- moviesUpdate . updateId
13+ await searchClient . MeiliSearchClient . index ( 'movies' ) . waitForTask (
14+ documentsTask . uid
1515 )
1616 } )
1717
@@ -43,18 +43,14 @@ describe('Instant MeiliSearch Browser test', () => {
4343 } ,
4444 } ,
4545 ] )
46- const notRetrieved = [
47- 'id' ,
48- 'overview' ,
49- 'genres' ,
50- 'poster' ,
51- 'release_date' ,
52- 'title' ,
53- ]
46+
5447 const hit = < Movies > response . results [ 0 ] . hits [ 0 ]
55- notRetrieved . map ( ( attribute : string ) =>
56- expect ( hit [ attribute ] ) . not . toBeDefined ( )
57- )
48+ expect ( hit . id ) . not . toBeDefined ( )
49+ expect ( hit . overview ) . not . toBeDefined ( )
50+ expect ( hit . genres ) . not . toBeDefined ( )
51+ expect ( hit . poster ) . not . toBeDefined ( )
52+ expect ( hit . release_date ) . not . toBeDefined ( )
53+ expect ( hit . title ) . not . toBeDefined ( )
5854 } )
5955
6056 test ( 'Test attributesToRetrieve on one non existing attribute' , async ( ) => {
@@ -67,20 +63,15 @@ describe('Instant MeiliSearch Browser test', () => {
6763 } ,
6864 } ,
6965 ] )
70- const notRetrieved = [
71- 'id' ,
72- 'overview' ,
73- 'genres' ,
74- 'poster' ,
75- 'release_date' ,
76- 'title' ,
77- ]
66+
7867 const hit = < Movies > response . results [ 0 ] . hits [ 0 ]
79- notRetrieved . map (
80- ( attribute : string ) =>
81- hit . _highlightResult &&
82- expect ( hit . _highlightResult [ attribute ] ) . toBeDefined ( )
83- )
68+
69+ expect ( hit . _highlightResult ?. id ) . toBeDefined ( )
70+ expect ( hit . _highlightResult ?. overview ) . toBeDefined ( )
71+ expect ( hit . _highlightResult ?. genres ) . toBeDefined ( )
72+ expect ( hit . _highlightResult ?. poster ) . toBeDefined ( )
73+ expect ( hit . _highlightResult ?. release_date ) . toBeDefined ( )
74+ expect ( hit . _highlightResult ?. title ) . toBeDefined ( )
8475 } )
8576
8677 test ( 'Test attributesToRetrieve on one existing attribute' , async ( ) => {
@@ -93,12 +84,14 @@ describe('Instant MeiliSearch Browser test', () => {
9384 } ,
9485 } ,
9586 ] )
96- const notRetrieved = [ 'id' , 'overview' , 'genres' , 'poster' , 'release_date' ]
9787 const hit = < Movies > response . results [ 0 ] . hits [ 0 ]
9888 expect ( hit . title ) . toEqual ( 'Ariel' )
99- notRetrieved . map ( ( attribute : string ) =>
100- expect ( hit [ attribute ] ) . not . toBeDefined ( )
101- )
89+ expect ( hit . id ) . not . toBeDefined ( )
90+ expect ( hit . overview ) . not . toBeDefined ( )
91+ expect ( hit . genres ) . not . toBeDefined ( )
92+ expect ( hit . poster ) . not . toBeDefined ( )
93+ expect ( hit . release_date ) . not . toBeDefined ( )
94+ expect ( hit . title ) . toBeDefined ( )
10295 } )
10396
10497 test ( 'Test attributesToRetrieve on default value' , async ( ) => {
@@ -110,18 +103,24 @@ describe('Instant MeiliSearch Browser test', () => {
110103 } ,
111104 } ,
112105 ] )
113- const notRetrieved = [ 'id' , 'overview' , 'genres' , 'poster' , 'release_date' ]
106+
114107 const hit = < Movies > response . results [ 0 ] . hits [ 0 ]
115108 expect ( hit . title ) . toEqual ( 'Ariel' )
116109 expect ( hit . _highlightResult ) . toBeDefined ( )
117- notRetrieved . map ( ( attribute : string ) =>
118- expect ( hit [ attribute ] ) . toBeDefined ( )
119- )
120- notRetrieved . map (
121- ( attribute : string ) =>
122- hit . _highlightResult &&
123- expect ( hit . _highlightResult [ attribute ] ) . toBeDefined ( )
124- )
110+
111+ expect ( hit . id ) . toBeDefined ( )
112+ expect ( hit . overview ) . toBeDefined ( )
113+ expect ( hit . genres ) . toBeDefined ( )
114+ expect ( hit . poster ) . toBeDefined ( )
115+ expect ( hit . release_date ) . toBeDefined ( )
116+ expect ( hit . title ) . toBeDefined ( )
117+
118+ expect ( hit . _highlightResult ?. id ) . toBeDefined ( )
119+ expect ( hit . _highlightResult ?. overview ) . toBeDefined ( )
120+ expect ( hit . _highlightResult ?. genres ) . toBeDefined ( )
121+ expect ( hit . _highlightResult ?. poster ) . toBeDefined ( )
122+ expect ( hit . _highlightResult ?. release_date ) . toBeDefined ( )
123+ expect ( hit . _highlightResult ?. title ) . toBeDefined ( )
125124 } )
126125
127126 test ( 'Test attributesToRetrieve on wild card' , async ( ) => {
@@ -134,21 +133,14 @@ describe('Instant MeiliSearch Browser test', () => {
134133 } ,
135134 } ,
136135 ] )
137- const retrieved = [
138- 'id' ,
139- 'overview' ,
140- 'genres' ,
141- 'poster' ,
142- 'release_date' ,
143- 'title' ,
144- ]
136+
145137 const hit = < Movies > response . results [ 0 ] . hits [ 0 ]
146138 expect ( hit . title ) . toEqual ( 'Ariel' )
147- retrieved . map ( ( attribute : string ) => expect ( hit [ attribute ] ) . toBeDefined ( ) )
148- retrieved . map (
149- ( attribute : string ) =>
150- hit . _highlightResult &&
151- expect ( hit . _highlightResult [ attribute ] ) . toBeDefined ( )
152- )
139+ expect ( hit . _highlightResult ?. id ) . toBeDefined ( )
140+ expect ( hit . _highlightResult ?. overview ) . toBeDefined ( )
141+ expect ( hit . _highlightResult ?. genres ) . toBeDefined ( )
142+ expect ( hit . _highlightResult ?. poster ) . toBeDefined ( )
143+ expect ( hit . _highlightResult ?. release_date ) . toBeDefined ( )
144+ expect ( hit . _highlightResult ?. title ) . toBeDefined ( )
153145 } )
154146} )
0 commit comments