Skip to content

Commit 3511588

Browse files
committed
Fix tests, misc
1 parent d9ac1f3 commit 3511588

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

src/token.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { TenantTokenGeneratorOptions, TokenSearchRules } from "./types";
33

44
function getOptionsWithDefaults(options: TenantTokenGeneratorOptions) {
55
const {
6-
searchRules = [],
6+
searchRules = ["*"],
77
algorithm = "HS256",
88
force = false,
99
...restOfOptions
@@ -154,7 +154,6 @@ function tryDetectEnvironment(): void {
154154
);
155155
}
156156

157-
// TODO: Add option of MeiliSearch instead of apiKeyUid? Or rather raise issue about it for now.
158157
/**
159158
* Generate a tenant token.
160159
*

src/types/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ export type TenantTokenGeneratorOptions = {
11351135
/**
11361136
* Search rules that are applied to every search.
11371137
*
1138-
* @defaultValue `[]`
1138+
* @defaultValue `["*"]`
11391139
*/
11401140
searchRules?: TokenSearchRules;
11411141
/**

tests/token.test.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ describe.each([{ permission: "Admin" }])(
144144

145145
expect(apiKeyUid).toEqual(uid);
146146
expect(exp).toBeUndefined();
147-
expect(searchRules).toEqual([]);
147+
expect(searchRules).toEqual(["*"]);
148148
});
149149

150150
test(`${permission} key: create a tenant token with array searchRules and test payload`, async () => {
@@ -192,7 +192,6 @@ describe.each([{ permission: "Admin" }])(
192192
const token = await generateTenantToken({
193193
apiKey,
194194
apiKeyUid: uid,
195-
searchRules: ["*"],
196195
});
197196

198197
const searchClient = new MeiliSearch({ host: HOST, apiKey: token });
@@ -214,7 +213,6 @@ describe.each([{ permission: "Admin" }])(
214213
const token = await generateTenantToken({
215214
apiKey: key,
216215
apiKeyUid: uid,
217-
searchRules: ["*"],
218216
});
219217

220218
const searchClient = new MeiliSearch({ host: HOST, apiKey: token });
@@ -231,7 +229,6 @@ describe.each([{ permission: "Admin" }])(
231229
const token = await generateTenantToken({
232230
apiKey,
233231
apiKeyUid: uid,
234-
searchRules: ["*"],
235232
expiresAt: date,
236233
});
237234

@@ -246,7 +243,7 @@ describe.each([{ permission: "Admin" }])(
246243
).resolves.not.toBeUndefined();
247244
});
248245

249-
test(`${permission} key: Search in tenant token with expireAt value set in the past`, async () => {
246+
test(`${permission} key: Search in tenant token with expireAt value set in the past throws an error on usage`, async () => {
250247
const client = await getClient(permission);
251248
const apiKey = await getKey(permission);
252249
const { uid } = await client.getKey(apiKey);
@@ -255,7 +252,6 @@ describe.each([{ permission: "Admin" }])(
255252
const token = await generateTenantToken({
256253
apiKey,
257254
apiKeyUid: uid,
258-
searchRules: ["*"],
259255
expiresAt: date,
260256
});
261257

@@ -316,6 +312,7 @@ describe.each([{ permission: "Admin" }])(
316312
const token = await generateTenantToken({
317313
apiKey,
318314
apiKeyUid: uid,
315+
searchRules: [],
319316
});
320317

321318
const searchClient = new MeiliSearch({ host: HOST, apiKey: token });
@@ -344,7 +341,7 @@ describe.each([{ permission: "Admin" }])(
344341
).rejects.toHaveProperty("cause.code", "invalid_api_key");
345342
});
346343

347-
test(`${permission} key: Creates tenant token with an expiration date as UNIX timestamp in the past throws an error`, async () => {
344+
test(`${permission} key: Creates tenant token with an expiration date as UNIX timestamp in the past throws an error on usage`, async () => {
348345
const client = await getClient(permission);
349346
const apiKey = await getKey(permission);
350347
const { uid } = await client.getKey(apiKey);

0 commit comments

Comments
 (0)