99}  from  './utils/meilisearch-test-utils' 
1010import  {  createHmac  }  from  'crypto' 
1111import  MeiliSearch  from  '../src' 
12- import  {  MeiliSearchError  }  from  '../src/errors' 
1312
1413const  HASH_ALGORITHM  =  'HS256' 
1514const  TOKEN_TYP  =  'JWT' 
@@ -44,7 +43,7 @@ describe.each([{ permission: 'Admin' }])(
4443      const  client  =  await  getClient ( permission ) 
4544      const  apiKey  =  await  getKey ( permission ) 
4645      const  {  uid }  =  await  client . getKey ( apiKey ) 
47-       const  token  =  client . generateTenantToken ( uid ,  [ ] ,  { } ) 
46+       const  token  =  await   client . generateTenantToken ( uid ,  [ ] ,  { } ) 
4847      const  [ header64 ]  =  token . split ( '.' ) 
4948
5049      // header 
@@ -57,7 +56,7 @@ describe.each([{ permission: 'Admin' }])(
5756      const  client  =  await  getClient ( permission ) 
5857      const  apiKey  =  await  getKey ( permission ) 
5958      const  {  uid }  =  await  client . getKey ( apiKey ) 
60-       const  token  =  client . generateTenantToken ( uid ,  [ ] ,  { } ) 
59+       const  token  =  await   client . generateTenantToken ( uid ,  [ ] ,  { } ) 
6160      const  [ header64 ,  payload64 ,  signature64 ]  =  token . split ( '.' ) 
6261
6362      // signature 
@@ -75,7 +74,7 @@ describe.each([{ permission: 'Admin' }])(
7574      const  client  =  await  getClient ( permission ) 
7675      const  apiKey  =  await  getKey ( permission ) 
7776      const  {  uid }  =  await  client . getKey ( apiKey ) 
78-       const  token  =  client . generateTenantToken ( uid ,  [ ] ,  { } ) 
77+       const  token  =  await   client . generateTenantToken ( uid ,  [ ] ,  { } ) 
7978      const  [ _ ,  payload64 ]  =  token . split ( '.' ) 
8079
8180      // payload 
@@ -90,7 +89,7 @@ describe.each([{ permission: 'Admin' }])(
9089      const  client  =  await  getClient ( permission ) 
9190      const  apiKey  =  await  getKey ( permission ) 
9291      const  {  uid }  =  await  client . getKey ( apiKey ) 
93-       const  token  =  client . generateTenantToken ( uid ,  [ UID ] ) 
92+       const  token  =  await   client . generateTenantToken ( uid ,  [ UID ] ) 
9493      const  [ _ ,  payload64 ]  =  token . split ( '.' ) 
9594
9695      // payload 
@@ -105,7 +104,7 @@ describe.each([{ permission: 'Admin' }])(
105104      const  client  =  await  getClient ( permission ) 
106105      const  apiKey  =  await  getKey ( permission ) 
107106      const  {  uid }  =  await  client . getKey ( apiKey ) 
108-       const  token  =  client . generateTenantToken ( uid ,  {  [ UID ] : { }  } ) 
107+       const  token  =  await   client . generateTenantToken ( uid ,  {  [ UID ] : { }  } ) 
109108      const  [ _ ,  payload64 ]  =  token . split ( '.' ) 
110109
111110      // payload 
@@ -120,7 +119,7 @@ describe.each([{ permission: 'Admin' }])(
120119      const  apiKey  =  await  getKey ( permission ) 
121120      const  {  uid }  =  await  client . getKey ( apiKey ) 
122121
123-       const  token  =  client . generateTenantToken ( uid ,  [ '*' ] ) 
122+       const  token  =  await   client . generateTenantToken ( uid ,  [ '*' ] ) 
124123
125124      const  searchClient  =  new  MeiliSearch ( {  host : HOST ,  apiKey : token  } ) 
126125
@@ -137,7 +136,7 @@ describe.each([{ permission: 'Admin' }])(
137136        indexes : [ UID ] , 
138137      } ) 
139138      const  client  =  await  getClient ( permission ) 
140-       const  token  =  client . generateTenantToken ( uid ,  [ '*' ] ,  { 
139+       const  token  =  await   client . generateTenantToken ( uid ,  [ '*' ] ,  { 
141140        apiKey : key , 
142141      } ) 
143142
@@ -152,7 +151,7 @@ describe.each([{ permission: 'Admin' }])(
152151      const  date  =  new  Date ( 'December 17, 4000 03:24:00' ) 
153152      const  apiKey  =  await  getKey ( permission ) 
154153      const  {  uid }  =  await  client . getKey ( apiKey ) 
155-       const  token  =  client . generateTenantToken ( uid ,  [ '*' ] ,  { 
154+       const  token  =  await   client . generateTenantToken ( uid ,  [ '*' ] ,  { 
156155        expiresAt : date , 
157156      } ) 
158157
@@ -171,18 +170,18 @@ describe.each([{ permission: 'Admin' }])(
171170      const  {  uid }  =  await  client . getKey ( apiKey ) 
172171      const  date  =  new  Date ( 'December 17, 2000 03:24:00' ) 
173172
174-       expect ( ( )   => 
175-         client . generateTenantToken ( uid ,  [ '*' ] ,  { 
176-            expiresAt :  date , 
177-         } ) 
178-       ) . toThrow ( ) 
173+       expect ( 
174+         client . generateTenantToken ( uid ,  [ '*' ] ,  {   expiresAt :  date   } ) 
175+       ) . rejects . toThrow ( 
176+         `Meilisearch: The expiresAt field must be a date in the future.` 
177+       ) 
179178    } ) 
180179
181180    test ( `${ permission }   key: Search in tenant token with specific index set to null` ,  async  ( )  =>  { 
182181      const  client  =  await  getClient ( permission ) 
183182      const  apiKey  =  await  getKey ( permission ) 
184183      const  {  uid }  =  await  client . getKey ( apiKey ) 
185-       const  token  =  client . generateTenantToken ( uid ,  { 
184+       const  token  =  await   client . generateTenantToken ( uid ,  { 
186185        [ UID ] : null , 
187186      } ) 
188187
@@ -202,7 +201,7 @@ describe.each([{ permission: 'Admin' }])(
202201      const  client  =  await  getClient ( permission ) 
203202      const  apiKey  =  await  getKey ( permission ) 
204203      const  {  uid }  =  await  client . getKey ( apiKey ) 
205-       const  token  =  client . generateTenantToken ( uid ,  { 
204+       const  token  =  await   client . generateTenantToken ( uid ,  { 
206205        [ UID ] : {  filter : 'id = 2'  } , 
207206      } ) 
208207
@@ -216,7 +215,7 @@ describe.each([{ permission: 'Admin' }])(
216215      const  client  =  await  getClient ( permission ) 
217216      const  apiKey  =  await  getKey ( permission ) 
218217      const  {  uid }  =  await  client . getKey ( apiKey ) 
219-       const  token  =  client . generateTenantToken ( uid ,  [ ] ) 
218+       const  token  =  await   client . generateTenantToken ( uid ,  [ ] ) 
220219
221220      const  searchClient  =  new  MeiliSearch ( {  host : HOST ,  apiKey : token  } ) 
222221
@@ -230,7 +229,7 @@ describe.each([{ permission: 'Admin' }])(
230229      const  client  =  await  getClient ( permission ) 
231230      const  apiKey  =  await  getKey ( permission ) 
232231      const  {  uid }  =  await  client . getKey ( apiKey ) 
233-       const  token  =  client . generateTenantToken ( uid ,  {  misc : null  } ) 
232+       const  token  =  await   client . generateTenantToken ( uid ,  {  misc : null  } ) 
234233
235234      const  searchClient  =  new  MeiliSearch ( {  host : HOST ,  apiKey : token  } ) 
236235
@@ -246,38 +245,32 @@ describe.each([{ permission: 'Admin' }])(
246245      const  {  uid }  =  await  client . getKey ( apiKey ) 
247246      const  date  =  new  Date ( 'December 17, 2000 03:24:00' ) 
248247
249-       expect ( ( )   => 
248+       expect ( 
250249        client . generateTenantToken ( 
251250          uid , 
252251          { } , 
253252          { 
254253            expiresAt : date , 
255254          } 
256255        ) 
257-       ) . toThrowError ( 
258-         new  MeiliSearchError ( 
259-           `Meilisearch: The expiresAt field must be a date in the future.` 
260-         ) 
256+       ) . rejects . toThrow ( 
257+         `Meilisearch: The expiresAt field must be a date in the future.` 
261258      ) 
262259    } ) 
263260
264261    test ( `${ permission }   key: Creates tenant token with wrong uid type throws an error` ,  async  ( )  =>  { 
265262      const  client  =  await  getClient ( permission ) 
266263
267-       expect ( ( )  =>  client . generateTenantToken ( '1234' ,  [ '*' ] ) ) . toThrowError ( 
268-         new  MeiliSearchError ( 
269-           `Meilisearch: The uid of your key is not a valid uuid4. To find out the uid of your key use getKey().` 
270-         ) 
264+       expect ( client . generateTenantToken ( '1234' ,  [ '*' ] ) ) . rejects . toThrow ( 
265+         `Meilisearch: The uid of your key is not a valid uuid4. To find out the uid of your key use getKey().` 
271266      ) 
272267    } ) 
273268
274269    test ( `${ permission }   key: Creates a tenant token with no api key in client and in parameters throws an error` ,  ( )  =>  { 
275270      const  client  =  new  MeiliSearch ( {  host : HOST  } ) 
276271
277-       expect ( ( )  =>  client . generateTenantToken ( '123' ,  [ ] ) ) . toThrowError ( 
278-         new  MeiliSearchError ( 
279-           `Meilisearch: The API key used for the token generation must exist and be of type string.` 
280-         ) 
272+       expect ( client . generateTenantToken ( '123' ,  [ ] ) ) . rejects . toThrow ( 
273+         `Meilisearch: The API key used for the token generation must exist and be of type string.` 
281274      ) 
282275    } ) 
283276  } 
0 commit comments