Improve user profile search (#1266)

* Filter account owner in UserDiscoveryService

* Add tests and refine logics
This commit is contained in:
Alfonso Grillo
2023-07-06 15:53:31 +02:00
committed by GitHub
parent 1de2a0b3e3
commit 3afb8fa867
2 changed files with 30 additions and 9 deletions
@@ -24,7 +24,7 @@ class UserDiscoveryServiceTest: XCTestCase {
var clientProxy: MockClientProxy!
override func setUpWithError() throws {
clientProxy = .init(userID: "")
clientProxy = .init(userID: "@foo:matrix.org")
service = UserDiscoveryService(clientProxy: clientProxy)
}
@@ -34,6 +34,13 @@ class UserDiscoveryServiceTest: XCTestCase {
let results = await (try? search(query: "AAA").get()) ?? []
assertSearchResults(results, toBe: 1)
}
func testOwnerIsFiltered() async throws {
clientProxy.searchUsersResult = .success(.init(results: [UserProfileProxy(userID: "@foo:matrix.org")], limited: true))
let results = await (try? search(query: "AAA").get()) ?? []
assertSearchResults(results, toBe: 0)
}
func testGetProfileIsNotCalled() async {
clientProxy.searchUsersResult = .success(.init(results: searchResults, limited: true))
@@ -43,6 +50,15 @@ class UserDiscoveryServiceTest: XCTestCase {
assertSearchResults(results, toBe: 3)
XCTAssertFalse(clientProxy.getProfileCalled)
}
func testGetProfileIsNotCalledForAccountOwnerID() async {
clientProxy.searchUsersResult = .success(.init(results: searchResults, limited: true))
clientProxy.getProfileResult = .success(.init(userID: "@alice:matrix.org"))
let results = await (try? search(query: "foo:matrix.org").get()) ?? []
assertSearchResults(results, toBe: 3)
XCTAssertFalse(clientProxy.getProfileCalled)
}
func testLocalResultShows() async {
clientProxy.searchUsersResult = .success(.init(results: searchResults, limited: true))