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

fix: All object endpoints need to be public #80

Merged
merged 3 commits into from
Mar 16, 2023
Merged

fix: All object endpoints need to be public #80

merged 3 commits into from
Mar 16, 2023

Conversation

cbaker6
Copy link
Member

@cbaker6 cbaker6 commented Mar 15, 2023

New Pull Request Checklist

Issue Description

Currently ParseUser.become() and ParseUser.linkCommand are broken due to changes with the endpoint creating in #62. This is due the changes in 62 that made the endpoint computed property required for all ParseObject's, but the endpoints for specialized ParseObject's like ParseUser, ParseInstallation had their endpoints internal to the SDK, resulting in the default endpoint in the Objectable protocol to be used outside of testing and by any developer. This causes some features not to work.

Approach

Make all endpoint's public to replace the default implementation in Objectable.

Added the tests below to ensure public access to the endpoints remain. Note that the SDK isn't @testable on purpose:

import ParseSwift
class ObjectEndpointTests: XCTestCase {
struct User: ParseUser {
//: These are required by ParseObject
var objectId: String?
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var originalData: Data?
// These are required by ParseUser
var username: String?
var email: String?
var emailVerified: Bool?
var password: String?
var authData: [String: [String: String]?]?
// Your custom keys
var customKey: String?
}
struct Installation: ParseInstallation {
var installationId: String?
var deviceType: String?
var deviceToken: String?
var badge: Int?
var timeZone: String?
var channels: [String]?
var appName: String?
var appIdentifier: String?
var appVersion: String?
var parseVersion: String?
var localeIdentifier: String?
var objectId: String?
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var originalData: Data?
var customKey: String?
}
struct Session<SessionUser: ParseUser>: ParseSession {
var sessionToken: String
var user: User
var restricted: Bool?
var createdWith: [String: String]
var installationId: String
var expiresAt: Date
var originalData: Data?
var objectId: String?
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
init() {
sessionToken = "hello"
user = User()
restricted = false
createdWith = ["yolo": "yaw"]
installationId = "yes"
expiresAt = Date()
}
}
struct Role<RoleUser: ParseUser>: ParseRole {
// required by ParseObject
var objectId: String?
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var originalData: Data?
// provided by Role
var name: String?
}
func testUser() async throws {
let objectId = "yarr"
var user = User()
XCTAssertEqual(user.endpoint.urlComponent, "/users")
user.objectId = objectId
XCTAssertEqual(user.endpoint.urlComponent, "/users/\(objectId)")
}
func testInstallation() async throws {
let objectId = "yarr"
var installation = Installation()
XCTAssertEqual(installation.endpoint.urlComponent, "/installations")
installation.objectId = objectId
XCTAssertEqual(installation.endpoint.urlComponent, "/installations/\(objectId)")
}
func testSession() throws {
var session = Session<User>()
XCTAssertEqual(session.endpoint.urlComponent, "/sessions")
session.objectId = "me"
XCTAssertEqual(session.endpoint.urlComponent, "/sessions/me")
}
func testRole() throws {
var role = try Role<User>(name: "Administrator")
XCTAssertEqual(role.endpoint.urlComponent, "/roles")
role.objectId = "me"
XCTAssertEqual(role.endpoint.urlComponent, "/roles/me")
}
}

TODOs before merging

  • Add tests
  • Add entry to changelog

@cbaker6 cbaker6 linked an issue Mar 15, 2023 that may be closed by this pull request
3 tasks
@codecov
Copy link

codecov bot commented Mar 15, 2023

Codecov Report

Merging #80 (a92d943) into main (abd413f) will increase coverage by 0.02%.
The diff coverage is 100.00%.

❗ Current head a92d943 differs from pull request most recent head 0dc6266. Consider uploading reports for the commit 0dc6266 to get more accurate results

@@            Coverage Diff             @@
##             main      #80      +/-   ##
==========================================
+ Coverage   90.55%   90.58%   +0.02%     
==========================================
  Files         169      169              
  Lines       15101    15098       -3     
==========================================
+ Hits        13675    13676       +1     
+ Misses       1426     1422       -4     
Impacted Files Coverage Δ
Sources/ParseSwift/Objects/ParseSession.swift 66.66% <ø> (ø)
Sources/ParseSwift/API/API.swift 99.41% <100.00%> (ø)
Sources/ParseSwift/Objects/ParseInstallation.swift 88.30% <100.00%> (-0.02%) ⬇️
Sources/ParseSwift/Objects/ParseRole.swift 88.00% <100.00%> (ø)
Sources/ParseSwift/Objects/ParseUser.swift 91.01% <100.00%> (-0.02%) ⬇️

... and 1 file with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@cbaker6 cbaker6 merged commit 6e81c2f into main Mar 16, 2023
@cbaker6 cbaker6 deleted the anonReal branch March 16, 2023 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

User.become with a sessionToken fails
1 participant