Skip to content
This repository has been archived by the owner on Feb 13, 2025. It is now read-only.

Commit

Permalink
MLIBZ-2520: Delete items properly with Auto Pagination (#298)
Browse files Browse the repository at this point in the history
* added test for deleted items with AP

* MLIBZ-2520: Clear the collection before loading pages with auto pagination

* Fix failing unit test
  • Loading branch information
thomasconner authored May 23, 2018
1 parent 824a312 commit 20d9081
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/core/datastore/sync/sync-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
});
});

Expand Down
25 changes: 25 additions & 0 deletions test/integration/tests/sync.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 20d9081

Please sign in to comment.