From 4032b16f102341c40c84f1b34e022b818148161d Mon Sep 17 00:00:00 2001 From: Victor Hugo Barros Date: Mon, 14 May 2018 16:14:44 -0400 Subject: [PATCH 1/2] MLIBZ-2490: pull with skip should not remove cached records --- Kinvey/Kinvey/PullOperation.swift | 2 +- Kinvey/KinveyTests/SyncStoreTests.swift | 70 +++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/Kinvey/Kinvey/PullOperation.swift b/Kinvey/Kinvey/PullOperation.swift index 17f4d92e4..21aaf90c6 100644 --- a/Kinvey/Kinvey/PullOperation.swift +++ b/Kinvey/Kinvey/PullOperation.swift @@ -39,7 +39,7 @@ internal class PullOperation: FindOperation where T: NSObject } override var mustRemoveCachedRecords: Bool { - return true + return isSkipAndLimitNil } } diff --git a/Kinvey/KinveyTests/SyncStoreTests.swift b/Kinvey/KinveyTests/SyncStoreTests.swift index 994ffbd91..bf22d1b9d 100644 --- a/Kinvey/KinveyTests/SyncStoreTests.swift +++ b/Kinvey/KinveyTests/SyncStoreTests.swift @@ -7095,4 +7095,74 @@ class SyncStoreTests: StoreTestCase { } } + func testPullWithSkip() { + signUp(client: self.client) + + var json = [JsonDictionary]() + for i in 1 ... 10 { + json.append([ + "_id" : UUID().uuidString, + "name" : UUID().uuidString, + "age" : i, + "_acl" : [ + "creator" : self.client.activeUser!.userId + ], + "_kmd" : [ + "lmt" : Date().toString(), + "ect" : Date().toString() + ] + ]) + } + + mockResponse { request in + let urlComponents = URLComponents(url: request.url!, resolvingAgainstBaseURL: false)! + switch urlComponents.path { + case "/appdata/_kid_/Person/": + if let skipString = urlComponents.queryItems?.filter({ $0.name == "skip" }).first?.value, + let skip = Int(skipString) + { + return HttpResponse(json: Array(json[skip...])) + } + return HttpResponse(json: json) + default: + return HttpResponse(statusCode: 404, data: Data()) + } + } + defer { + setURLProtocol(nil) + } + + let dataStore = DataStore.collection(.sync) + + do { + var results = try dataStore.pull(options: nil).waitForResult(timeout: defaultTimeout).value() + XCTAssertEqual(results.count, json.count) + results = try dataStore.find().waitForResult(timeout: defaultTimeout).value() + XCTAssertEqual(results.count, json.count) + } catch { + XCTFail(error.localizedDescription) + } + + do { + let skip = 2 + let query = Query() + query.skip = skip + var results = try dataStore.pull(query, options: nil).waitForResult(timeout: defaultTimeout).value() + XCTAssertEqual(results.count, json.count - skip) + results = try dataStore.find().waitForResult(timeout: defaultTimeout).value() + XCTAssertEqual(results.count, json.count) + } catch { + XCTFail(error.localizedDescription) + } + + do { + var results = try dataStore.pull(options: nil).waitForResult(timeout: defaultTimeout).value() + XCTAssertEqual(results.count, json.count) + results = try dataStore.find().waitForResult(timeout: defaultTimeout).value() + XCTAssertEqual(results.count, json.count) + } catch { + XCTFail(error.localizedDescription) + } + } + } From 11c1527043a92b29cbf3c116964d9b3775ddf7fd Mon Sep 17 00:00:00 2001 From: Victor Hugo Barros Date: Tue, 15 May 2018 12:01:23 -0400 Subject: [PATCH 2/2] mock delta set requests as Martin suggested in the JIRA ticket --- Kinvey/KinveyTests/SyncStoreTests.swift | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Kinvey/KinveyTests/SyncStoreTests.swift b/Kinvey/KinveyTests/SyncStoreTests.swift index bf22d1b9d..e692c0531 100644 --- a/Kinvey/KinveyTests/SyncStoreTests.swift +++ b/Kinvey/KinveyTests/SyncStoreTests.swift @@ -7121,10 +7121,25 @@ class SyncStoreTests: StoreTestCase { if let skipString = urlComponents.queryItems?.filter({ $0.name == "skip" }).first?.value, let skip = Int(skipString) { - return HttpResponse(json: Array(json[skip...])) + return HttpResponse( + headerFields: ["X-Kinvey-Request-Start" : Date().toString()], + json: Array(json[skip...]) + ) } - return HttpResponse(json: json) + return HttpResponse( + headerFields: ["X-Kinvey-Request-Start" : Date().toString()], + json: json + ) + case "/appdata/_kid_/Person/_deltaset": + return HttpResponse( + headerFields: ["X-Kinvey-Request-Start" : Date().toString()], + json: [ + "changed" : [], + "deleted" : [] + ] + ) default: + XCTFail(urlComponents.path) return HttpResponse(statusCode: 404, data: Data()) } } @@ -7132,7 +7147,7 @@ class SyncStoreTests: StoreTestCase { setURLProtocol(nil) } - let dataStore = DataStore.collection(.sync) + let dataStore = DataStore.collection(.sync, options: Options(deltaSet: true)) do { var results = try dataStore.pull(options: nil).waitForResult(timeout: defaultTimeout).value()