commit 0af02a2cf74853812090f0229cd7e1f58e8ac3f1
parent 94653e1b16249616c21e0af745a9134a6659be5f
Author: Florian Dold <dold@taler.net>
Date: Wed, 22 Jul 2026 21:43:28 +0200
idb-bridge: test getIndexKeys against the multiEntry semantics
Diffstat:
1 file changed, 29 insertions(+), 9 deletions(-)
diff --git a/packages/idb-bridge/src/util/getIndexKeys.test.ts b/packages/idb-bridge/src/util/getIndexKeys.test.ts
@@ -32,21 +32,41 @@ test("basics", (t) => {
assert.deepStrictEqual(getIndexKeys({ foo: 42 }, "foo.bar", false), []);
- assert.deepStrictEqual(getIndexKeys({ foo: 42 }, "foo", true), [42]);
- assert.deepStrictEqual(
- getIndexKeys({ foo: 42, bar: 10 }, ["foo", "bar"], true),
- [42, 10],
- );
assert.deepStrictEqual(
getIndexKeys({ foo: 42, bar: 10 }, ["foo", "bar"], false),
[[42, 10]],
);
- assert.deepStrictEqual(
- getIndexKeys({ foo: 42, bar: 10 }, ["foo", "bar", "spam"], true),
- [42, 10],
- );
assert.throws(() => {
getIndexKeys({ foo: 42, bar: 10 }, ["foo", "bar", "spam"], false);
});
});
+
+test("multiEntry", (t) => {
+ // A multiEntry index has a string key path whose value is an array, and
+ // indexes every element separately. (createIndex rejects multiEntry with
+ // an array key path, so that combination never reaches here.)
+ assert.deepStrictEqual(
+ getIndexKeys({ foo: [42, 43] }, "foo", true),
+ [42, 43],
+ );
+
+ // Duplicates are recorded once.
+ assert.deepStrictEqual(
+ getIndexKeys({ foo: [42, 43, 42] }, "foo", true),
+ [42, 43],
+ );
+
+ // Elements that are not valid keys are skipped, they don't fail the record.
+ assert.deepStrictEqual(
+ getIndexKeys({ foo: [42, null, {}, NaN, "spam"] }, "foo", true),
+ [42, "spam"],
+ );
+
+ // A value that isn't an array behaves like an ordinary single-key index.
+ assert.deepStrictEqual(getIndexKeys({ foo: 42 }, "foo", true), [42]);
+
+ // Nothing at the key path, or a value that is not a valid key: no entry.
+ assert.deepStrictEqual(getIndexKeys({ foo: 42 }, "bar", true), []);
+ assert.deepStrictEqual(getIndexKeys({ foo: {} }, "foo", true), []);
+});