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

[WIP] Add tests for different storage platforms with actual mocks (SQLite, idb-keyval) #528

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
update test
  • Loading branch information
chrispader committed Mar 29, 2024
commit 1538e885bcee92cb8cdc229dec040b7ad43658fc
25 changes: 17 additions & 8 deletions tests/unit/onyxTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1089,9 +1089,15 @@ describe('Onyx', () => {
f: 'f',
c: {
g: 'g',
h: 'h',
},
};
const changes = [change1, change2];
const change3 = {
c: {
g: null,
},
};
const changes = [change1, change2, change3];

const batchedChanges = OnyxUtils.applyMerge(undefined, changes, false);

Expand All @@ -1106,26 +1112,29 @@ describe('Onyx', () => {
return Onyx.set(ONYX_KEYS.TEST_KEY, initialData)
.then(() => {
expect(result).toEqual(initialData);
Onyx.merge(ONYX_KEYS.TEST_KEY, changes[0]);
Onyx.merge(ONYX_KEYS.TEST_KEY, changes[1]);

_.map(changes, (change) => Onyx.merge(ONYX_KEYS.TEST_KEY, change));
})
.then(waitForPromisesToResolve)
.then(() => {
const valueInStorage = StorageMock.getItem(ONYX_KEYS.TEST_KEY);

console.log('Result from Onyx (most likely from cache)\n', JSON.stringify(result, null, 2));
console.log('Result in storage\n', JSON.stringify(valueInStorage, null, 2));

expect(result).toEqual({
f: 'f',
c: {
g: 'g',
h: 'h',
},
});

console.log('Result in storage\n', JSON.stringify(result, null, 2));

// We would need to mock SQLite here to actually see what happens
// The current storage mock will just use the "modifiedData" from Onyx and just set it instead of actually applying the delta change.
expect(StorageMock.getItem(ONYX_KEYS.TEST_KEY)).toEqual({
expect(valueInStorage).toEqual({
f: 'f',
c: {
g: 'g',
h: 'h',
},
});
});
Expand Down