Skip to content

fix: throw .missingObjectId error when fetching #300

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

Merged
merged 2 commits into from
Dec 12, 2021
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
12 changes: 6 additions & 6 deletions Sources/ParseSwift/API/API+Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ internal extension API {
currentNotificationQueue = callbackQueue
}
if !path.urlComponent.contains("/files/") {
//All ParseObjects use the shared URLSession
// All ParseObjects use the shared URLSession
switch self.prepareURLRequest(options: options,
childObjects: childObjects,
childFiles: childFiles) {
Expand Down Expand Up @@ -395,7 +395,6 @@ internal extension API.Command {
return create(object)
}

// MARK: Saving ParseObjects - private
static func create<T>(_ object: T) -> API.Command<T, T> where T: ParseObject {
var object = object
if object.ACL == nil,
Expand Down Expand Up @@ -439,10 +438,11 @@ internal extension API.Command {
mapper: mapper)
}

// MARK: Fetching
// MARK: Fetching ParseObjects
static func fetch<T>(_ object: T, include: [String]?) throws -> API.Command<T, T> where T: ParseObject {
guard object.objectId != nil else {
throw ParseError(code: .unknownError, message: "Cannot Fetch an object without id")
throw ParseError(code: .missingObjectId,
message: "objectId must not be nil")
}

var params: [String: String]?
Expand All @@ -462,7 +462,7 @@ internal extension API.Command {

internal extension API.Command where T: ParseObject {

// MARK: Batch - Saving, Fetching
// MARK: Batch - Saving, Fetching ParseObjects
static func batch(commands: [API.Command<T, T>],
transaction: Bool) -> RESTBatchCommandType<T> {
let batchCommands = commands.compactMap { (command) -> API.Command<T, T>? in
Expand Down Expand Up @@ -514,7 +514,7 @@ internal extension API.Command where T: ParseObject {
return RESTBatchCommandType<T>(method: .POST, path: .batch, body: batchCommand, mapper: mapper)
}

// MARK: Batch - Deleting
// MARK: Batch - Deleting ParseObjects
static func batch(commands: [API.NonParseBodyCommand<NoBody, NoBody>],
transaction: Bool) -> RESTBatchCommandNoBodyType<NoBody> {
let commands = commands.compactMap { (command) -> API.NonParseBodyCommand<NoBody, NoBody>? in
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/Objects/ParseInstallation+combine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public extension ParseInstallation {

- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: A publisher that eventually produces a single value and then finishes or fails.
- important: If an object replcaed has the same objectId as current, it will automatically replace the current.
- important: If an object replaced has the same objectId as current, it will automatically replace the current.
*/
func replacePublisher(options: API.Options = []) -> Future<Self, ParseError> {
Future { promise in
Expand Down
3 changes: 2 additions & 1 deletion Sources/ParseSwift/Objects/ParseInstallation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ extension ParseInstallation {

func fetchCommand(include: [String]?) throws -> API.Command<Self, Self> {
guard objectId != nil else {
throw ParseError(code: .unknownError, message: "Cannot fetch an object without id")
throw ParseError(code: .missingObjectId,
message: "objectId must not be nil")
}

var params: [String: String]?
Expand Down
3 changes: 2 additions & 1 deletion Sources/ParseSwift/Objects/ParseUser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,8 @@ extension ParseUser {

func fetchCommand(include: [String]?) throws -> API.Command<Self, Self> {
guard objectId != nil else {
throw ParseError(code: .unknownError, message: "Cannot fetch an object without id")
throw ParseError(code: .missingObjectId,
message: "objectId must not be nil")
}

var params: [String: String]?
Expand Down
8 changes: 4 additions & 4 deletions Tests/ParseSwiftTests/ParseAnalyticsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class ParseAnalyticsTests: XCTestCase {
#if canImport(AppTrackingTransparency)
func testTrackAppOpenedUIKitNotAuthorized() {
if #available(macOS 11.0, iOS 14.0, macCatalyst 14.0, tvOS 14.0, *) {
ParseSwift.configuration.isTestingSDK = false //Allow authorization check
ParseSwift.configuration.isTestingSDK = false // Allow authorization check
let expectation = XCTestExpectation(description: "Analytics save")
let options = [UIApplication.LaunchOptionsKey.remoteNotification: ["stop": "drop"]]
ParseAnalytics.trackAppOpened(launchOptions: options) { result in
Expand Down Expand Up @@ -192,7 +192,7 @@ class ParseAnalyticsTests: XCTestCase {
#if canImport(AppTrackingTransparency)
func testTrackAppOpenedNotAuthorized() {
if #available(macOS 11.0, iOS 14.0, macCatalyst 14.0, tvOS 14.0, *) {
ParseSwift.configuration.isTestingSDK = false //Allow authorization check
ParseSwift.configuration.isTestingSDK = false // Allow authorization check
let expectation = XCTestExpectation(description: "Analytics save")
ParseAnalytics.trackAppOpened(dimensions: ["stop": "drop"]) { result in

Expand Down Expand Up @@ -317,7 +317,7 @@ class ParseAnalyticsTests: XCTestCase {
#if canImport(AppTrackingTransparency)
func testTrackEventNotAuthorized() {
if #available(macOS 11.0, iOS 14.0, macCatalyst 14.0, tvOS 14.0, *) {
ParseSwift.configuration.isTestingSDK = false //Allow authorization check
ParseSwift.configuration.isTestingSDK = false // Allow authorization check

let expectation = XCTestExpectation(description: "Analytics save")
let event = ParseAnalytics(name: "hello")
Expand All @@ -338,7 +338,7 @@ class ParseAnalyticsTests: XCTestCase {

func testTrackEventNotAuthorizedMutated() {
if #available(macOS 11.0, iOS 14.0, macCatalyst 14.0, tvOS 14.0, *) {
ParseSwift.configuration.isTestingSDK = false //Allow authorization check
ParseSwift.configuration.isTestingSDK = false // Allow authorization check

let expectation = XCTestExpectation(description: "Analytics save")
var event = ParseAnalytics(name: "hello")
Expand Down
4 changes: 1 addition & 3 deletions Tests/ParseSwiftTests/ParseInstallationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@ class ParseInstallationTests: XCTestCase { // swiftlint:disable:this type_body_l
}
installation.objectId = testInstallationObjectId
installation.createdAt = Calendar.current.date(byAdding: .init(day: -1), to: Date())
installation.updatedAt = Calendar.current.date(byAdding: .init(day: -1), to: Date())
installation.ACL = nil

var installationOnServer = installation
Expand Down Expand Up @@ -400,7 +399,6 @@ class ParseInstallationTests: XCTestCase { // swiftlint:disable:this type_body_l
}
installation.objectId = testInstallationObjectId
installation.createdAt = Calendar.current.date(byAdding: .init(day: -1), to: Date())
installation.updatedAt = Calendar.current.date(byAdding: .init(day: -1), to: Date())
installation.ACL = nil

var installationOnServer = installation
Expand Down Expand Up @@ -551,7 +549,6 @@ class ParseInstallationTests: XCTestCase { // swiftlint:disable:this type_body_l
return
}
installation.objectId = testInstallationObjectId
installation.createdAt = Calendar.current.date(byAdding: .init(day: -1), to: Date())
installation.updatedAt = Calendar.current.date(byAdding: .init(day: -1), to: Date())
installation.ACL = nil

Expand Down Expand Up @@ -581,6 +578,7 @@ class ParseInstallationTests: XCTestCase { // swiftlint:disable:this type_body_l

func testFetchCommand() {
var installation = Installation()
XCTAssertThrowsError(try installation.fetchCommand(include: nil))
let objectId = "yarr"
installation.objectId = objectId
do {
Expand Down
1 change: 1 addition & 0 deletions Tests/ParseSwiftTests/ParseObjectTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length
func testFetchCommand() {
var score = GameScore(score: 10)
let className = score.className
XCTAssertThrowsError(try score.fetchCommand(include: nil))
let objectId = "yarr"
score.objectId = objectId
do {
Expand Down
1 change: 1 addition & 0 deletions Tests/ParseSwiftTests/ParseSessionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class ParseSessionTests: XCTestCase {

func testFetchCommand() throws {
var session = Session<User>()
XCTAssertThrowsError(try session.fetchCommand(include: nil))
session.objectId = "me"
do {
let command = try session.fetchCommand(include: nil)
Expand Down
1 change: 1 addition & 0 deletions Tests/ParseSwiftTests/ParseUserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class ParseUserTests: XCTestCase { // swiftlint:disable:this type_body_length

func testFetchCommand() {
var user = User()
XCTAssertThrowsError(try user.fetchCommand(include: nil))
let objectId = "yarr"
user.objectId = objectId
do {
Expand Down