Skip to content

Commit

Permalink
Fix compilation issue
Browse files Browse the repository at this point in the history
  • Loading branch information
shilgapira committed Jan 15, 2024
1 parent 16240a2 commit 5927e5f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/types/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,14 @@ extension DescopeUser: CustomStringConvertible {

extension DescopeUser: Equatable {
public static func == (lhs: DescopeUser, rhs: DescopeUser) -> Bool {
let lhca = lhs.customAttributes as NSDictionary
let rhca = rhs.customAttributes as NSDictionary
let attrs = lhs.customAttributes as NSDictionary
return lhs.userId == rhs.userId && lhs.loginIds == rhs.loginIds &&
lhs.createdAt == rhs.createdAt && lhs.picture == rhs.picture &&
lhs.email == rhs.email && lhs.isVerifiedEmail == rhs.isVerifiedEmail &&
lhs.phone == rhs.phone && lhs.isVerifiedPhone == rhs.isVerifiedPhone &&
lhs.name == rhs.name && lhs.givenName == rhs.givenName &&
lhs.middleName == rhs.middleName && lhs.familyName == rhs.familyName &&
lhca.isEqual(to: rhca)
attrs.isEqual(to: rhs.customAttributes)
}
}

Expand Down
29 changes: 26 additions & 3 deletions test/types/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,36 @@ import XCTest

class TestUser: XCTestCase {
func testUserEncoding() throws {
let user = DescopeUser(userId: "userId", loginIds: ["loginId"], createdAt: Date(), email: "email", isVerifiedEmail: true, customAttributes: ["a": "yes"])
var user = DescopeUser(
userId: "userId",
loginIds: ["loginId"],
createdAt: Date(),
email: "email",
isVerifiedEmail: true,
customAttributes: ["a": "yes"]
)

let encodedUser = try JSONEncoder().encode(user)
let decodedUser = try JSONDecoder().decode(DescopeUser.self, from: encodedUser)
XCTAssertEqual(user, decodedUser)

XCTAssertTrue(decodedUser.isVerifiedEmail)
XCTAssertFalse(decodedUser.isVerifiedPhone)
guard let aValue = decodedUser.customAttributes["a"] as? String else { return XCTFail("Couldn't get custom attirubte value as String") }
guard let aValue = decodedUser.customAttributes["a"] as? String else { return XCTFail("Couldn't get custom attribute value as String") }
XCTAssertEqual("yes", aValue)

XCTAssertEqual(user, decodedUser)
XCTAssertTrue(user == decodedUser)

user.customAttributes["a"] = TestUser()
XCTAssertNotEqual(user, decodedUser)
XCTAssertTrue(user != decodedUser)

user.customAttributes["a"] = "no"
XCTAssertNotEqual(user, decodedUser)
XCTAssertTrue(user != decodedUser)

user.customAttributes["a"] = "yes"
XCTAssertEqual(user, decodedUser)
XCTAssertTrue(user == decodedUser)
}
}

0 comments on commit 5927e5f

Please sign in to comment.