Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luacmartins committed Jul 12, 2023
1 parent 69ec6e9 commit ad1a66d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/Onyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ function mergeCollection(collectionKey, collection) {
return;
}
hasCollectionKeyCheckFailed = true;
Logger.logError(`Provided collection doesn't have all its data belonging to the same parent. CollectionKey: ${collectionKey}, DataKey: ${dataKey}`);
Logger.logAlert(`Provided collection doesn't have all its data belonging to the same parent. CollectionKey: ${collectionKey}, DataKey: ${dataKey}`);
});

// Gracefully handle bad mergeCollection updates so it doesn't block the merge queue
Expand Down
18 changes: 12 additions & 6 deletions tests/unit/onyxTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,18 @@ describe('Onyx', () => {
});
});

it('should throw error when a key not belonging to collection key is present in mergeCollection', () => {
try {
Onyx.mergeCollection(ONYX_KEYS.COLLECTION.TEST_KEY, {test_1: {ID: 123}, notMyTest: {beep: 'boop'}});
} catch (error) {
expect(error.message).toEqual(`Provided collection doesn't have all its data belonging to the same parent. CollectionKey: ${ONYX_KEYS.COLLECTION.TEST_KEY}, DataKey: notMyTest`);
}
it('should skip the update when a key not belonging to collection key is present in mergeCollection', () => {
const valuesReceived = {};
connectionID = Onyx.connect({
key: ONYX_KEYS.COLLECTION.TEST_KEY,
initWithStoredValues: false,
callback: (data, key) => valuesReceived[key] = data,
});

return Onyx.mergeCollection(ONYX_KEYS.COLLECTION.TEST_KEY, {test_1: {ID: 123}, notMyTest: {beep: 'boop'}})
.then(() => {
expect(valuesReceived).toEqual({});
});
});

it('should return full object to callback when calling mergeCollection()', () => {
Expand Down

0 comments on commit ad1a66d

Please sign in to comment.