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

MLIBZ-2490: pull with skip should not remove cached records #287

Merged
merged 2 commits into from
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Kinvey/Kinvey/PullOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal class PullOperation<T: Persistable>: FindOperation<T> where T: NSObject
}

override var mustRemoveCachedRecords: Bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this get called? Can you link to a line number?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PullOperation extends from FindOperation, here's the line in FindOperation:

if self.mustRemoveCachedRecords {

return true
return isSkipAndLimitNil
}

}
85 changes: 85 additions & 0 deletions Kinvey/KinveyTests/SyncStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7095,4 +7095,89 @@ 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(
headerFields: ["X-Kinvey-Request-Start" : Date().toString()],
json: Array(json[skip...])
)
}
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())
}
}
defer {
setURLProtocol(nil)
}

let dataStore = DataStore<Person>.collection(.sync, options: Options(deltaSet: true))

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)
}
}

}