From 20d90817fdc64ebdb2d5451d2b5e0ee4f7c84136 Mon Sep 17 00:00:00 2001 From: Thomas Conner Date: Wed, 23 May 2018 13:52:08 -0400 Subject: [PATCH] MLIBZ-2520: Delete items properly with Auto Pagination (#298) * added test for deleted items with AP * MLIBZ-2520: Clear the collection before loading pages with auto pagination * Fix failing unit test --- src/core/datastore/sync/sync-manager.js | 2 +- .../sync-manager.spec.js | 7 ++---- test/integration/tests/sync.test.js | 25 +++++++++++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/core/datastore/sync/sync-manager.js b/src/core/datastore/sync/sync-manager.js index a4a701479..0fe4355ca 100644 --- a/src/core/datastore/sync/sync-manager.js +++ b/src/core/datastore/sync/sync-manager.js @@ -473,7 +473,7 @@ export class SyncManager { return this._getExpectedEntityCount(collection, userQuery) .then(({ lastRequest, count }) => { pullQuery = this._getInternalPullQuery(userQuery, count); - return this._deleteOfflineEntities(collection, pullQuery) + return this._deleteOfflineEntities(collection) .then(() => { const pageSizeSetting = options.autoPagination && options.autoPagination.pageSize; const pageSize = pageSizeSetting || maxEntityLimit; diff --git a/src/core/datastore/working-with-data-tests/sync-manager.spec.js b/src/core/datastore/working-with-data-tests/sync-manager.spec.js index 6d23f549c..1cbd299a5 100644 --- a/src/core/datastore/working-with-data-tests/sync-manager.spec.js +++ b/src/core/datastore/working-with-data-tests/sync-manager.spec.js @@ -378,14 +378,11 @@ describe('SyncManager delegating to repos and SyncStateManager', () => { }); }); - it('should call OfflineRepo.delete() with the internal pull query', () => { + it('should call OfflineRepo.delete() without a query', () => { utilsMock.splitQueryIntoPages = expect.createSpy().andReturn([]); return syncManager.pull(collection, null, options) .then(() => { - const internalQueryMock = new Query(); - internalQueryMock.limit = backendEntityCount; - internalQueryMock.sort = { [defaultSortField]: 1 }; - validateSpyCalls(offlineRepoMock.delete, 1, [collection, internalQueryMock]); + validateSpyCalls(offlineRepoMock.delete, 1, [collection, undefined]); }); }); diff --git a/test/integration/tests/sync.test.js b/test/integration/tests/sync.test.js index 8c712b634..4242dfb48 100644 --- a/test/integration/tests/sync.test.js +++ b/test/integration/tests/sync.test.js @@ -415,6 +415,31 @@ function testFunc() { .catch(done); }); + it('should delete entities locally that are deleted in the server with autopagination', (done) => { + let query = new Kinvey.Query(); + storeToTest.pull(query, {autoPagination:{pageSize:1}}) + .then((result) => validatePullOperation(result, [entity1, entity2])) + .then(() => networkStore.save(entity3)) + .then(() => storeToTest.pull(query, {autoPagination:true})) + .then((result) => validatePullOperation(result, [entity1, entity2, entity3])) + .then(() => networkStore.removeById(entity1._id)) + .then(() => networkStore.removeById(entity2._id)) + .then(() => storeToTest.pull(query, {autoPagination:true})) + .then((result) => validatePullOperation(result, [entity3])) + .then(() => { + let onNextSpy = sinon.spy(); + syncStore.find() + .subscribe(onNextSpy, done, () => { + try { + utilities.validateReadResult(Kinvey.DataStoreType.Sync, onNextSpy, [entity3]) + done(); + } catch (error) { + done(error) + }}) + }) + .catch(done); + }); + it('should pull only the entities, matching the query', (done) => { const query = new Kinvey.Query(); query.equalTo('_id', entity1._id);