Skip to content

Commit

Permalink
ADD test for #4775
Browse files Browse the repository at this point in the history
  • Loading branch information
pubkey committed Jul 12, 2023
1 parent c2c855f commit 677a231
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
73 changes: 73 additions & 0 deletions test/unit/rx-collection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
16 changes: 16 additions & 0 deletions test/unit/rx-storage-query-correctness.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,13 +705,29 @@ 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',
integer: 1,
number: 1,
boolean: true,
null: null
},
{
id: 'two',
nonPrimaryString: 'two',
integer: 2,
number: 2,
boolean: false,
null: 'not-null'
}
],
schema: {
Expand Down

0 comments on commit 677a231

Please sign in to comment.