-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IOS-8527. First and Last name are not being saved when account is cre…
…ated and confirmed
- Loading branch information
Showing
11 changed files
with
547 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
@testable import MEGA | ||
|
||
public final class MockMOUser { | ||
var firstname: String? | ||
var lastname: String? | ||
var nickname: String? | ||
var email: String? | ||
|
||
public init(firstname: String? = nil, lastname: String? = nil, nickname: String? = nil, email: String? = nil) { | ||
self.firstname = firstname | ||
self.lastname = lastname | ||
self.nickname = nickname | ||
self.email = email | ||
} | ||
|
||
public func toMOUser(context: NSManagedObjectContext) -> MOUser { | ||
let moUser = NSEntityDescription.insertNewObject(forEntityName: "User", into: context) as! MOUser | ||
|
||
moUser.firstname = self.firstname | ||
moUser.lastname = self.lastname | ||
moUser.nickname = self.nickname | ||
moUser.email = self.email | ||
|
||
return moUser | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
MEGAUnitTests/Mocks/Utils/UserAttributes/MockUserAttributesMEGAStore.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
@testable import MEGA | ||
|
||
public final class MockUserAttributesMEGAStore: MEGAStore, @unchecked Sendable { | ||
public let currentContext: NSManagedObjectContext | ||
|
||
// In-memory storage for users, using handles as keys | ||
private var users: [UInt64: MockMOUser] = [:] | ||
|
||
public init(currentContext: NSManagedObjectContext) { | ||
self.currentContext = currentContext | ||
} | ||
|
||
// MARK: - Fetch MockMOUser by Handle | ||
public override func fetchUser(withUserHandle userHandle: UInt64, context: NSManagedObjectContext) -> MOUser? { | ||
users[userHandle]?.toMOUser(context: currentContext) | ||
} | ||
|
||
public override func fetchUser(withUserHandle userHandle: UInt64) -> MOUser? { | ||
users[userHandle]?.toMOUser(context: currentContext) | ||
} | ||
|
||
public override func fetchUser(withEmail email: String) -> MOUser? { | ||
firstUser(withEmail: email)?.toMOUser(context: currentContext) | ||
} | ||
|
||
public override func insertUser(withUserHandle handle: UInt64, firstname: String?, lastname: String?, nickname: String?, email: String?) { | ||
let newUser = MockMOUser(firstname: firstname, lastname: lastname, nickname: nickname, email: email) | ||
users[handle] = newUser | ||
} | ||
|
||
public override func updateUser(withUserHandle handle: UInt64, firstname: String) { | ||
updateUser(handle: handle, updateBlock: { user in | ||
user.firstname = firstname | ||
}) | ||
} | ||
|
||
public override func updateUser(withUserHandle handle: UInt64, lastname: String) { | ||
updateUser(handle: handle, updateBlock: { user in | ||
user.lastname = lastname | ||
}) | ||
} | ||
|
||
public override func updateUser(withUserHandle handle: UInt64, nickname: String) { | ||
updateUser(handle: handle, updateBlock: { user in | ||
user.nickname = nickname | ||
}) | ||
} | ||
|
||
public override func updateUser(withEmail email: String, firstname: String) { | ||
if let handle = handleForUser(withEmail: email) { | ||
updateUser(handle: handle, updateBlock: { user in | ||
user.firstname = firstname | ||
}) | ||
} | ||
} | ||
|
||
public override func updateUser(withEmail email: String, lastname: String) { | ||
if let handle = handleForUser(withEmail: email) { | ||
updateUser(handle: handle, updateBlock: { user in | ||
user.lastname = lastname | ||
}) | ||
} | ||
} | ||
|
||
public override func updateUser(withEmail email: String, nickname: String) { | ||
if let handle = handleForUser(withEmail: email) { | ||
updateUser(handle: handle, updateBlock: { user in | ||
user.nickname = nickname | ||
}) | ||
} | ||
} | ||
|
||
func firstUser(withEmail email: String) -> MockMOUser? { | ||
users.values.first { $0.email == email } | ||
} | ||
|
||
func handleForUser(withEmail email: String) -> UInt64? { | ||
users.first { $0.value.email == email }?.key | ||
} | ||
|
||
private func updateUser(handle: UInt64, updateBlock: (inout MockMOUser) -> Void) { | ||
if var user = users[handle] { | ||
updateBlock(&user) | ||
users[handle] = user | ||
} | ||
} | ||
} |
Oops, something went wrong.