mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
fix(healthchat): refresh the account status whenever settings appears
The banner kept telling the user to complete a profile they had just completed, and nothing was fetched until the screen was actually shown.
This commit is contained in:
@@ -60,10 +60,53 @@ final class HealthChatAccountStatusLoaderTests {
|
||||
#expect(await status() == .unknown)
|
||||
}
|
||||
|
||||
@Test
|
||||
func fetchesNothingUntilAsked() throws {
|
||||
apiService.ownProfileReturnValue = try .success(makeMember(isApproved: false))
|
||||
|
||||
let loader = HealthChatAccountStatusLoader(apiService: apiService)
|
||||
|
||||
#expect(loader.status == .unknown)
|
||||
#expect(apiService.ownProfileCallsCount == 0)
|
||||
}
|
||||
|
||||
@Test
|
||||
func loadingAgainReflectsTheNewServerState() async throws {
|
||||
apiService.ownProfileReturnValue = try .success(makeMember(isApproved: true))
|
||||
apiService.profileCompletenessReturnValue = try .success(makeCompleteness(isComplete: false,
|
||||
message: "Profil unvollständig"))
|
||||
let loader = HealthChatAccountStatusLoader(apiService: apiService)
|
||||
loader.load()
|
||||
await loader.loadingTask?.value
|
||||
#expect(loader.status == .incompleteProfile(message: "Profil unvollständig"))
|
||||
|
||||
apiService.profileCompletenessReturnValue = try .success(makeCompleteness(isComplete: true, message: nil))
|
||||
loader.load()
|
||||
await loader.loadingTask?.value
|
||||
|
||||
#expect(loader.status == .ok)
|
||||
}
|
||||
|
||||
@Test
|
||||
func aFailedReloadKeepsTheLastKnownStatus() async throws {
|
||||
apiService.ownProfileReturnValue = try .success(makeMember(isApproved: false))
|
||||
let loader = HealthChatAccountStatusLoader(apiService: apiService)
|
||||
loader.load()
|
||||
await loader.loadingTask?.value
|
||||
#expect(loader.status == .pendingApproval)
|
||||
|
||||
apiService.ownProfileReturnValue = .failure(.networkFailure)
|
||||
loader.load()
|
||||
await loader.loadingTask?.value
|
||||
|
||||
#expect(loader.status == .pendingApproval)
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private func status() async -> HealthChatAccountStatus {
|
||||
let loader = HealthChatAccountStatusLoader(apiService: apiService)
|
||||
loader.load()
|
||||
await loader.loadingTask?.value
|
||||
return loader.status
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user