diff --git a/test/unit/rx-collection.test.ts b/test/unit/rx-collection.test.ts index ab7d581e842..40396dd0d9b 100644 --- a/test/unit/rx-collection.test.ts +++ b/test/unit/rx-collection.test.ts @@ -1261,6 +1261,79 @@ describe('rx-collection.test.ts', () => { c.database.destroy(); }); }); + /** + * @link https://github.com/pubkey/rxdb/pull/4775 + */ + it('#4775 count() broken on primary key', async () => { + // create a schema + const mySchema = { + version: 0, + primaryKey: 'passportId', + type: 'object', + properties: { + passportId: { + type: 'string', + maxLength: 100 + }, + firstName: { + type: 'string' + }, + lastName: { + type: 'string' + }, + age: { + type: 'integer', + minimum: 0, + maximum: 150 + } + } + }; + + const name = randomCouchString(10); + const db = await createRxDatabase({ + name, + storage: config.storage.getStorage(), + eventReduce: true, + ignoreDuplicate: true + }); + const collections = await db.addCollections({ + mycollection: { + schema: mySchema + } + }); + + // insert a document + await collections.mycollection.insert({ + passportId: 'foobar2', + firstName: 'Bob', + lastName: 'Kelso', + age: 56 + }); + await collections.mycollection.insert({ + passportId: 'foobar3', + firstName: 'Bob', + lastName: 'Kelso', + age: 56 + }); + + const countResult = await collections.mycollection + .count({ + selector: { + passportId: { + $eq: 'foobar' + } + } + }).exec(); + + /* + * assert things, + * here your tests should fail to show that there is a bug + */ + assert.strictEqual(countResult, 0); + + // clean up afterwards + db.destroy(); + }); }); config.parallel('.bulkUpsert()', () => { it('insert and update', async () => { diff --git a/test/unit/rx-storage-query-correctness.test.ts b/test/unit/rx-storage-query-correctness.test.ts index 7a80c491bb8..cd1a3c9efcb 100644 --- a/test/unit/rx-storage-query-correctness.test.ts +++ b/test/unit/rx-storage-query-correctness.test.ts @@ -705,6 +705,14 @@ config.parallel('rx-storage-query-correctness.test.ts', () => { testCorrectQueries({ testTitle: '$eq operator', data: [ + { + id: 'zero', + nonPrimaryString: 'zero', + integer: 0, + number: 0, + boolean: false, + null: 'not-null' + }, { id: 'one', nonPrimaryString: 'one', @@ -712,6 +720,14 @@ config.parallel('rx-storage-query-correctness.test.ts', () => { number: 1, boolean: true, null: null + }, + { + id: 'two', + nonPrimaryString: 'two', + integer: 2, + number: 2, + boolean: false, + null: 'not-null' } ], schema: {