From f9f7bd8874e88cfb2a83ccb5dfccf1f9f876ef46 Mon Sep 17 00:00:00 2001 From: pubkey <8926560+pubkey@users.noreply.github.com> Date: Wed, 19 Jul 2023 16:21:36 +0200 Subject: [PATCH] ADD test for #4755 $regex not working correctly --- test/unit/rx-query.test.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/unit/rx-query.test.ts b/test/unit/rx-query.test.ts index 5fa551a3c71..9f84c3de449 100644 --- a/test/unit/rx-query.test.ts +++ b/test/unit/rx-query.test.ts @@ -1136,6 +1136,31 @@ describe('rx-query.test.ts', () => { c.database.destroy(); }); + /** + * @link https://github.com/pubkey/rxdb/issues/4755#issuecomment-1641928515 + */ + it('#4755 $regex on primaryKey not working correctly', async () => { + const c = await humansCollection.create(0); + + await c.bulkInsert([ + schemaObjects.human('hello1'), + schemaObjects.human('hello2'), + schemaObjects.human('hello22'), + schemaObjects.human('hello3') + ]); + + const queryResult = await c.find({ + selector: { + passportId: { + $regex: '^hello2' + } + } + }).exec(); + assert.strictEqual(queryResult.length, 2); + queryResult.forEach(doc => assert.ok(doc.passportId.startsWith('hello2'))); + + c.database.destroy(); + }); it('#2213 prepareQuery should handle all comparison operators', async () => { const collection = await humansCollection.createAgeIndex(0); await collection.insert({