Skip to content
Open
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
32 changes: 24 additions & 8 deletions Sources/ParseSwift/Objects/ParseInstallation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,9 @@ extension ParseInstallation {
ignoringCustomObjectIdConfig: ignoringCustomObjectIdConfig,
options: options,
callbackQueue: callbackQueue)
completion(.success(object))
callbackQueue.async {
completion(.success(object))
}
} catch {
let defaultError = ParseError(code: .unknownError,
message: error.localizedDescription)
Expand Down Expand Up @@ -741,7 +743,9 @@ extension ParseInstallation {
let object = try await command(method: method,
options: options,
callbackQueue: callbackQueue)
completion(.success(object))
callbackQueue.async {
completion(.success(object))
}
} catch {
let defaultError = ParseError(code: .unknownError,
message: error.localizedDescription)
Expand Down Expand Up @@ -782,7 +786,9 @@ extension ParseInstallation {
let object = try await command(method: method,
options: options,
callbackQueue: callbackQueue)
completion(.success(object))
callbackQueue.async {
completion(.success(object))
}
} catch {
let defaultError = ParseError(code: .unknownError,
message: error.localizedDescription)
Expand Down Expand Up @@ -823,7 +829,9 @@ extension ParseInstallation {
let object = try await command(method: method,
options: options,
callbackQueue: callbackQueue)
completion(.success(object))
callbackQueue.async {
completion(.success(object))
}
} catch {
let defaultError = ParseError(code: .unknownError,
message: error.localizedDescription)
Expand Down Expand Up @@ -1207,7 +1215,9 @@ public extension Sequence where Element: ParseInstallation {
ignoringCustomObjectIdConfig: ignoringCustomObjectIdConfig,
options: options,
callbackQueue: callbackQueue)
completion(.success(objects))
callbackQueue.async {
completion(.success(objects))
}
} catch {
let defaultError = ParseError(code: .unknownError,
message: error.localizedDescription)
Expand Down Expand Up @@ -1261,7 +1271,9 @@ public extension Sequence where Element: ParseInstallation {
transaction: transaction,
options: options,
callbackQueue: callbackQueue)
completion(.success(objects))
callbackQueue.async {
completion(.success(objects))
}
} catch {
let defaultError = ParseError(code: .unknownError,
message: error.localizedDescription)
Expand Down Expand Up @@ -1315,7 +1327,9 @@ public extension Sequence where Element: ParseInstallation {
transaction: transaction,
options: options,
callbackQueue: callbackQueue)
completion(.success(objects))
callbackQueue.async {
completion(.success(objects))
}
} catch {
let defaultError = ParseError(code: .unknownError,
message: error.localizedDescription)
Expand Down Expand Up @@ -1369,7 +1383,9 @@ public extension Sequence where Element: ParseInstallation {
transaction: transaction,
options: options,
callbackQueue: callbackQueue)
completion(.success(objects))
callbackQueue.async {
completion(.success(objects))
}
} catch {
let defaultError = ParseError(code: .unknownError,
message: error.localizedDescription)
Expand Down
32 changes: 24 additions & 8 deletions Sources/ParseSwift/Objects/ParseObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,9 @@ transactions for this call.
ignoringCustomObjectIdConfig: ignoringCustomObjectIdConfig,
options: options,
callbackQueue: callbackQueue)
completion(.success(objects))
callbackQueue.async {
completion(.success(objects))
}
} catch {
let defaultError = ParseError(code: .unknownError,
message: error.localizedDescription)
Expand Down Expand Up @@ -569,7 +571,9 @@ transactions for this call.
transaction: transaction,
options: options,
callbackQueue: callbackQueue)
completion(.success(objects))
callbackQueue.async {
completion(.success(objects))
}
} catch {
let defaultError = ParseError(code: .unknownError,
message: error.localizedDescription)
Expand Down Expand Up @@ -622,7 +626,9 @@ transactions for this call.
transaction: transaction,
options: options,
callbackQueue: callbackQueue)
completion(.success(objects))
callbackQueue.async {
completion(.success(objects))
}
} catch {
let defaultError = ParseError(code: .unknownError,
message: error.localizedDescription)
Expand Down Expand Up @@ -675,7 +681,9 @@ transactions for this call.
transaction: transaction,
options: options,
callbackQueue: callbackQueue)
completion(.success(objects))
callbackQueue.async {
completion(.success(objects))
}
} catch {
let defaultError = ParseError(code: .unknownError,
message: error.localizedDescription)
Expand Down Expand Up @@ -1213,7 +1221,9 @@ extension ParseObject {
ignoringCustomObjectIdConfig: ignoringCustomObjectIdConfig,
options: options,
callbackQueue: callbackQueue)
completion(.success(object))
callbackQueue.async {
completion(.success(object))
}
} catch {
let defaultError = ParseError(code: .unknownError,
message: error.localizedDescription)
Expand Down Expand Up @@ -1252,7 +1262,9 @@ extension ParseObject {
let object = try await command(method: method,
options: options,
callbackQueue: callbackQueue)
completion(.success(object))
callbackQueue.async {
completion(.success(object))
}
} catch {
let defaultError = ParseError(code: .unknownError,
message: error.localizedDescription)
Expand Down Expand Up @@ -1290,7 +1302,9 @@ extension ParseObject {
let object = try await command(method: method,
options: options,
callbackQueue: callbackQueue)
completion(.success(object))
callbackQueue.async {
completion(.success(object))
}
} catch {
let defaultError = ParseError(code: .unknownError,
message: error.localizedDescription)
Expand Down Expand Up @@ -1328,7 +1342,9 @@ extension ParseObject {
let object = try await command(method: method,
options: options,
callbackQueue: callbackQueue)
completion(.success(object))
callbackQueue.async {
completion(.success(object))
}
} catch {
let defaultError = ParseError(code: .unknownError,
message: error.localizedDescription)
Expand Down
32 changes: 24 additions & 8 deletions Sources/ParseSwift/Objects/ParseUser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,9 @@ extension ParseUser {
ignoringCustomObjectIdConfig: ignoringCustomObjectIdConfig,
options: options,
callbackQueue: callbackQueue)
completion(.success(object))
callbackQueue.async {
completion(.success(object))
}
} catch {
let defaultError = ParseError(code: .unknownError,
message: error.localizedDescription)
Expand Down Expand Up @@ -1154,7 +1156,9 @@ extension ParseUser {
let object = try await command(method: method,
options: options,
callbackQueue: callbackQueue)
completion(.success(object))
callbackQueue.async {
completion(.success(object))
}
} catch {
let defaultError = ParseError(code: .unknownError,
message: error.localizedDescription)
Expand Down Expand Up @@ -1193,7 +1197,9 @@ extension ParseUser {
let object = try await command(method: method,
options: options,
callbackQueue: callbackQueue)
completion(.success(object))
callbackQueue.async {
completion(.success(object))
}
} catch {
let defaultError = ParseError(code: .unknownError,
message: error.localizedDescription)
Expand Down Expand Up @@ -1232,7 +1238,9 @@ extension ParseUser {
let object = try await command(method: method,
options: options,
callbackQueue: callbackQueue)
completion(.success(object))
callbackQueue.async {
completion(.success(object))
}
} catch {
let defaultError = ParseError(code: .unknownError,
message: error.localizedDescription)
Expand Down Expand Up @@ -1637,7 +1645,9 @@ public extension Sequence where Element: ParseUser {
ignoringCustomObjectIdConfig: ignoringCustomObjectIdConfig,
options: options,
callbackQueue: callbackQueue)
completion(.success(objects))
callbackQueue.async {
completion(.success(objects))
}
} catch {
let defaultError = ParseError(code: .unknownError,
message: error.localizedDescription)
Expand Down Expand Up @@ -1691,7 +1701,9 @@ public extension Sequence where Element: ParseUser {
transaction: transaction,
options: options,
callbackQueue: callbackQueue)
completion(.success(objects))
callbackQueue.async {
completion(.success(objects))
}
} catch {
let defaultError = ParseError(code: .unknownError,
message: error.localizedDescription)
Expand Down Expand Up @@ -1745,7 +1757,9 @@ public extension Sequence where Element: ParseUser {
transaction: transaction,
options: options,
callbackQueue: callbackQueue)
completion(.success(objects))
callbackQueue.async {
completion(.success(objects))
}
} catch {
let defaultError = ParseError(code: .unknownError,
message: error.localizedDescription)
Expand Down Expand Up @@ -1799,7 +1813,9 @@ public extension Sequence where Element: ParseUser {
transaction: transaction,
options: options,
callbackQueue: callbackQueue)
completion(.success(objects))
callbackQueue.async {
completion(.success(objects))
}
} catch {
let defaultError = ParseError(code: .unknownError,
message: error.localizedDescription)
Expand Down
40 changes: 40 additions & 0 deletions Tests/ParseSwiftTests/ParseObjectTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,46 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length
self.saveAsync(score: score, scoreOnServer: scoreOnServer, callbackQueue: .main)
}

func testSaveAsyncCallbackQueueOnSuccess() {
let score = GameScore(points: 10)

var scoreOnServer = score
scoreOnServer.objectId = "yarr"
scoreOnServer.createdAt = Date()
scoreOnServer.ACL = nil
let encoded: Data!
do {
encoded = try ParseCoding.jsonEncoder().encode(scoreOnServer)
//Get dates in correct format from ParseDecoding strategy
scoreOnServer = try scoreOnServer.getDecoder().decode(GameScore.self, from: encoded)
} catch {
XCTFail("Should have encoded/decoded: Error: \(error)")
return
}
MockURLProtocol.mockRequests { _ in
return MockURLResponse(data: encoded, statusCode: 200, delay: 0.0)
}

let callbackKey = DispatchSpecificKey<String>()
let callbackValue = "parse-object-save-success"
let callbackQueue = DispatchQueue(label: "com.parse.tests.object.save.success")
callbackQueue.setSpecific(key: callbackKey, value: callbackValue)

let expectation1 = XCTestExpectation(description: "Save object on callbackQueue")
score.save(options: [], callbackQueue: callbackQueue) { result in
XCTAssertEqual(DispatchQueue.getSpecific(key: callbackKey), callbackValue)
switch result {

case .success(let saved):
XCTAssert(saved.hasSameObjectId(as: scoreOnServer))
case .failure(let error):
XCTFail(error.localizedDescription)
}
expectation1.fulfill()
}
wait(for: [expectation1], timeout: 20.0)
}

func updateAsync(score: GameScore, scoreOnServer: GameScore, callbackQueue: DispatchQueue) {

let expectation1 = XCTestExpectation(description: "Update object1")
Expand Down
46 changes: 46 additions & 0 deletions Tests/ParseSwiftTests/ParseUserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,52 @@ class ParseUserTests: XCTestCase { // swiftlint:disable:this type_body_length
wait(for: [expectation1], timeout: 20.0)
}

func testSaveAsyncCallbackQueueOnSuccess() throws {
XCTAssertNil(User.current?.objectId)
try userSignUp()
XCTAssertNotNil(User.current?.objectId)

guard let user = User.current else {
XCTFail("Should unwrap")
return
}
var userOnServer = user
userOnServer.createdAt = nil
userOnServer.updatedAt = User.current?.updatedAt?.addingTimeInterval(+300)

let encoded: Data!
do {
encoded = try userOnServer.getEncoder().encode(userOnServer, skipKeys: .none)
//Get dates in correct format from ParseDecoding strategy
userOnServer = try userOnServer.getDecoder().decode(User.self, from: encoded)
} catch {
XCTFail("Should encode/decode. Error \(error)")
return
}
MockURLProtocol.mockRequests { _ in
return MockURLResponse(data: encoded, statusCode: 200, delay: 0.0)
}

let callbackKey = DispatchSpecificKey<String>()
let callbackValue = "parse-user-save-success"
let callbackQueue = DispatchQueue(label: "com.parse.tests.user.save.success")
callbackQueue.setSpecific(key: callbackKey, value: callbackValue)

let expectation1 = XCTestExpectation(description: "Save user on callbackQueue")
user.save(options: [], callbackQueue: callbackQueue) { result in
XCTAssertEqual(DispatchQueue.getSpecific(key: callbackKey), callbackValue)
switch result {

case .success(let saved):
XCTAssert(saved.hasSameObjectId(as: userOnServer))
case .failure(let error):
XCTFail(error.localizedDescription)
}
expectation1.fulfill()
}
wait(for: [expectation1], timeout: 20.0)
}

func testSaveAsyncAndUpdateCurrentUserModifiedEmail() throws { // swiftlint:disable:this function_body_length
XCTAssertNil(User.current?.objectId)
try userSignUp()
Expand Down