From e0bf8e6faf58c8120738215a1aa05adbd79289c3 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 11 Apr 2023 16:36:01 +0200 Subject: fix(ext/kv): keys must be arrays (#18655) There was some leftover code from previous iterations, where keys could be single parts instead of arrays also. This didn't match the types. --- cli/tests/unit/kv_test.ts | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'cli/tests') diff --git a/cli/tests/unit/kv_test.ts b/cli/tests/unit/kv_test.ts index 69eb8bed9..60cf11b8e 100644 --- a/cli/tests/unit/kv_test.ts +++ b/cli/tests/unit/kv_test.ts @@ -1138,6 +1138,51 @@ dbTest("operation size limit", async (db) => { ); }); +dbTest("keys must be arrays", async (db) => { + await assertRejects( + // @ts-expect-error invalid type + async () => await db.get("a"), + TypeError, + ); + + await assertRejects( + // @ts-expect-error invalid type + async () => await db.getMany(["a"]), + TypeError, + ); + + await assertRejects( + // @ts-expect-error invalid type + async () => await db.set("a", 1), + TypeError, + ); + + await assertRejects( + // @ts-expect-error invalid type + async () => await db.delete("a"), + TypeError, + ); + + await assertRejects( + async () => + await db.atomic() + // @ts-expect-error invalid type + .mutate({ key: "a", type: "set", value: 1 } satisfies Deno.KvMutation) + .commit(), + TypeError, + ); + + await assertRejects( + async () => + await db.atomic() + // @ts-expect-error invalid type + .check({ key: "a", versionstamp: null }) + .set(["a"], 1) + .commit(), + TypeError, + ); +}); + // This function is never called, it is just used to check that all the types // are behaving as expected. async function _typeCheckingTests() { -- cgit v1.2.3