From 0270d68da11ab865dcf50436e934cf85477f75ae Mon Sep 17 00:00:00 2001 From: Wojciech Trocki Date: Fri, 10 May 2019 18:51:06 +0100 Subject: [PATCH] fix: Integration tests --- packages/sync/integration_test/test/offline.test.js | 10 +++++----- packages/sync/integration_test/utils/testStore.js | 4 +++- packages/sync/src/offline/OfflineMutationsHandler.ts | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/sync/integration_test/test/offline.test.js b/packages/sync/integration_test/test/offline.test.js index a6d1167b..09087d5a 100644 --- a/packages/sync/integration_test/test/offline.test.js +++ b/packages/sync/integration_test/test/offline.test.js @@ -73,7 +73,7 @@ describe('Offline mutations', function () { } catch (ignore) { } - const offlineKeys = await JSON.parse(store.getItem(offlineMetaKey)); + const offlineKeys = await store.getItem(offlineMetaKey); const offlineMutation = await store.getItem("offline:" + offlineKeys[0]); expect(offlineMutation).to.exist; @@ -146,7 +146,7 @@ describe('Offline mutations', function () { }); } catch (ignore) { } - const offlineKeys = await JSON.parse(store.getItem(offlineMetaKey)); + const offlineKeys = await store.getItem(offlineMetaKey); const offlineMutation1 = await store.getItem("offline:" + offlineKeys[0]); const offlineMutation2 = await store.getItem("offline:" + offlineKeys[1]); @@ -349,7 +349,7 @@ describe('Offline mutations', function () { }); } catch (ignore) { } - const offlineKeys = await JSON.parse(store.getItem(offlineMetaKey)); + const offlineKeys = await store.getItem(offlineMetaKey); const offlineMutation1 = await store.getItem("offline:" + offlineKeys[0]); const offlineMutation2 = await store.getItem("offline:" + offlineKeys[1]); @@ -409,7 +409,7 @@ describe('Offline mutations', function () { }); } catch (ignore) { } - const offlineKeys = await JSON.parse(store.getItem(offlineMetaKey)); + const offlineKeys = await store.getItem(offlineMetaKey); const offlineMutation1 = await store.getItem("offline:" + offlineKeys[0]); const offlineMutation2 = await store.getItem("offline:" + offlineKeys[1]); @@ -479,7 +479,7 @@ describe('Offline mutations', function () { }); } catch (ignore) { } - const offlineKeys = await JSON.parse(store.getItem(offlineMetaKey)); + const offlineKeys = await store.getItem(offlineMetaKey); const offlineMutation = await store.getItem("offline:" + offlineKeys[0]); expect(offlineMutation).to.exist; networkStatus.setOnline(true); diff --git a/packages/sync/integration_test/utils/testStore.js b/packages/sync/integration_test/utils/testStore.js index e7671fe6..aa7e05af 100644 --- a/packages/sync/integration_test/utils/testStore.js +++ b/packages/sync/integration_test/utils/testStore.js @@ -4,14 +4,16 @@ export class TestStore { } getItem(key) { - return this.data[key]; + return Promise.resolve(this.data[key]); } setItem(key, data) { this.data[key] = data; + return Promise.resolve(); } removeItem(key) { delete this.data[key]; + return Promise.resolve(); } } diff --git a/packages/sync/src/offline/OfflineMutationsHandler.ts b/packages/sync/src/offline/OfflineMutationsHandler.ts index fa945dd6..29f24c8d 100644 --- a/packages/sync/src/offline/OfflineMutationsHandler.ts +++ b/packages/sync/src/offline/OfflineMutationsHandler.ts @@ -34,7 +34,7 @@ export class OfflineMutationsHandler { public replayOfflineMutations = async () => { const offlineData = await this.store.getOfflineData(); // if there is no offline data then just exit - if (offlineData.length === 0) { return; } + if (offlineData && offlineData.length === 0) { return; } logger("Replying offline mutations after application restart"); for (const item of offlineData) {