Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test key-compressed collection change events when object key is added containing square brackets #5603

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 41 additions & 32 deletions test/unit/bug-report.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
createRxDatabase,
randomCouchString
} from '../../plugins/core/index.mjs';
import { wrappedKeyCompressionStorage } from '../../plugins/key-compression/index.mjs';
import {
isNode
} from '../../plugins/test-utils/index.mjs';
Expand All @@ -42,6 +43,7 @@
version: 0,
primaryKey: 'passportId',
type: 'object',
keyCompression: true,
properties: {
passportId: {
type: 'string',
Expand All @@ -57,6 +59,17 @@
type: 'integer',
minimum: 0,
maximum: 150
},
tags: {
type: 'object',
patternProperties: {
'.*': {
properties: {
name: { type: 'string' },
},
required: ['name'],
}
},
}
}
};
Expand All @@ -74,68 +87,64 @@
* By calling config.storage.getStorage(),
* we can ensure that all variations of RxStorage are tested in the CI.
*/
storage: config.storage.getStorage(),
storage: wrappedKeyCompressionStorage({ storage: config.storage.getStorage() }),
eventReduce: true,
ignoreDuplicate: true
});
// create a collection
const collections = await db.addCollections({
mycollection: {
schema: mySchema
}
},
});

// insert a document
await collections.mycollection.insert({
passportId: 'foobar',
firstName: 'Bob',
lastName: 'Kelso',
age: 56
});

/**
* to simulate the event-propagation over multiple browser-tabs,
* we create the same database again
*/
const dbInOtherTab = await createRxDatabase({
name,
storage: config.storage.getStorage(),
eventReduce: true,
ignoreDuplicate: true
});
// create a collection
const collectionInOtherTab = await dbInOtherTab.addCollections({
mycollection: {
schema: mySchema
age: 56,
tags: {
example: 'example',
}
});

// find the document in the other tab
const myDocument = await collectionInOtherTab.mycollection
.findOne()
.where('firstName')
.eq('Bob')
.exec();
// find the document
let myDocument = await collections.mycollection.findOne().exec(true);

/*
* assert things,
* here your tests should fail to show that there is a bug
*/
assert.strictEqual(myDocument.age, 56);
assert.strictEqual(myDocument.tags.example, 'example');


// you can also wait for events
const emitted = [];

Check failure on line 123 in test/unit/bug-report.test.ts

View workflow job for this annotation

GitHub Actions / test-code-style

Variable 'emitted' implicitly has type 'any[]' in some locations where its type cannot be determined.
const sub = collectionInOtherTab.mycollection
.findOne().$
.subscribe(doc => {
emitted.push(doc);
});
const sub = collections.mycollection.$.subscribe((eventData) => {
emitted.push(eventData);
});

await myDocument.incrementalModify((docData) => {

Check failure on line 128 in test/unit/bug-report.test.ts

View workflow job for this annotation

GitHub Actions / test-code-style

Parameter 'docData' implicitly has an 'any' type.
const newDocData = Object.assign({}, docData);
newDocData.tags['[example2]'] = '[example2]';
return newDocData;
});

myDocument = await collections.mycollection.findOne().exec(true);
const tags = myDocument.toJSON().tags;
const expectedTags = {
example: 'example',
'[example2]': '[example2]',
};
assert.deepEqual(tags, expectedTags);

await AsyncTestUtil.waitUntil(() => emitted.length === 1);
assert.strictEqual(emitted[0].operation, 'UPDATE');

Check failure on line 143 in test/unit/bug-report.test.ts

View workflow job for this annotation

GitHub Actions / test-code-style

Variable 'emitted' implicitly has an 'any[]' type.
assert.deepEqual(emitted[0].documentData.tags, expectedTags);

Check failure on line 144 in test/unit/bug-report.test.ts

View workflow job for this annotation

GitHub Actions / test-code-style

Variable 'emitted' implicitly has an 'any[]' type.

// clean up afterwards
sub.unsubscribe();
db.destroy();
dbInOtherTab.destroy();
});
});
Loading