This respects the `giftBadges` capability when trying to send gift badges. In other words, it prevents you from sending gift badges to someone who lacks the capability. The bulk of this change involves fetching and saving of this new capability. The rest of the code involves showing it on the "choose recipient" screen (and some debug screens).
74 lines
2.6 KiB
Swift
74 lines
2.6 KiB
Swift
//
|
|
// Copyright (c) 2022 Open Whisper Systems. All rights reserved.
|
|
//
|
|
|
|
import XCTest
|
|
@testable import Signal
|
|
@testable import SignalMessaging
|
|
@testable import SignalServiceKit
|
|
|
|
class OWSProfileManagerTest: SignalBaseTest {
|
|
private lazy var localAddress = CommonGenerator.address()
|
|
|
|
override func setUp() {
|
|
super.setUp()
|
|
// Create local account.
|
|
tsAccountManager.registerForTests(withLocalNumber: localAddress.phoneNumber!,
|
|
uuid: localAddress.uuid!)
|
|
}
|
|
|
|
private func add(username: String, transaction: SDSAnyWriteTransaction) -> OWSUserProfile {
|
|
let profile = OWSUserProfile(address: SignalServiceAddress(uuid: UUID()))
|
|
profile.update(username: username,
|
|
isStoriesCapable: true,
|
|
canReceiveGiftBadges: true,
|
|
userProfileWriter: .tests,
|
|
transaction: transaction)
|
|
return profile
|
|
}
|
|
|
|
func testGetUsernames() {
|
|
let profileManager = OWSProfileManager(databaseStorage: databaseStorage)
|
|
var addresses: [SignalServiceAddress] = []
|
|
write { transaction in
|
|
for username in ["alice", "bob"] {
|
|
let profile = self.add(username: username, transaction: transaction)
|
|
addresses.append(profile.address)
|
|
}
|
|
}
|
|
read { transaction in
|
|
let bogus = SignalServiceAddress(uuid: UUID())
|
|
let actual = profileManager.usernames(forAddresses: addresses + [bogus], transaction: transaction).map {
|
|
$0.stringOrNil
|
|
}
|
|
let expected = ["alice", "bob", nil]
|
|
XCTAssertEqual(actual, expected)
|
|
}
|
|
}
|
|
|
|
func testGetUsername() {
|
|
let profileManager = OWSProfileManager(databaseStorage: databaseStorage)
|
|
var address: SignalServiceAddress!
|
|
write { transaction in
|
|
let profile = self.add(username: "alice", transaction: transaction)
|
|
address = profile.address
|
|
}
|
|
read { transaction in
|
|
let actual = profileManager.username(for: address, transaction: transaction).map {
|
|
$0.stringOrNil
|
|
}
|
|
let expected = "alice"
|
|
XCTAssertEqual(actual, expected)
|
|
}
|
|
}
|
|
|
|
func testGetUsername_Fail() {
|
|
let profileManager = OWSProfileManager(databaseStorage: databaseStorage)
|
|
read { transaction in
|
|
let address = SignalServiceAddress(uuid: UUID())
|
|
let maybeUsername = profileManager.username(for: address, transaction: transaction)
|
|
XCTAssertNil(maybeUsername)
|
|
}
|
|
}
|
|
}
|