aboutsummaryrefslogtreecommitdiffstats
path: root/packages/trpc/routers/apiKeys.test.ts
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2025-09-14 16:31:08 +0000
committerMohamed Bassem <me@mbassem.com>2025-09-14 16:31:08 +0000
commit7671f4ff7ac5b106c3faa6b59a01f154cb34be99 (patch)
treef9445fd05de16117a6f9fb6941a7f0f359d6618d /packages/trpc/routers/apiKeys.test.ts
parent69ef2ffe5e9216b0c0690221fc5679baabdc93ea (diff)
downloadkarakeep-7671f4ff7ac5b106c3faa6b59a01f154cb34be99.tar.zst
feat: Regen api keys
Diffstat (limited to 'packages/trpc/routers/apiKeys.test.ts')
-rw-r--r--packages/trpc/routers/apiKeys.test.ts31
1 files changed, 31 insertions, 0 deletions
diff --git a/packages/trpc/routers/apiKeys.test.ts b/packages/trpc/routers/apiKeys.test.ts
index b3e57db3..1fd2159a 100644
--- a/packages/trpc/routers/apiKeys.test.ts
+++ b/packages/trpc/routers/apiKeys.test.ts
@@ -141,6 +141,37 @@ describe("API Keys Routes", () => {
);
});
});
+ describe("regenerate", () => {
+ test<CustomTestContext>("revokes API key successfully", async ({
+ unauthedAPICaller,
+ db,
+ }) => {
+ const user = await unauthedAPICaller.users.create({
+ name: "Test User",
+ email: "test@test.com",
+ password: "password123",
+ confirmPassword: "password123",
+ });
+
+ const api = getApiCaller(db, user.id, user.email).apiKeys;
+
+ const firstKey = await api.create({ name: "Test Key" });
+ const regeneratedKey = await api.regenerate({ id: firstKey.id });
+
+ // Validate the new key
+ const validationResult = await unauthedAPICaller.apiKeys.validate({
+ apiKey: regeneratedKey.key,
+ });
+ expect(validationResult.success).toBe(true);
+
+ // Validate the old key is revoked
+ await expect(() =>
+ unauthedAPICaller.apiKeys.validate({
+ apiKey: firstKey.key,
+ }),
+ ).rejects.toThrow();
+ });
+ });
describe("revoke", () => {
test<CustomTestContext>("revokes API key successfully", async ({