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:
Sedat Qaja
2026-10-12 11:40:42 +02:00
parent d01d04846a
commit be803d0542
6 changed files with 71 additions and 9 deletions
@@ -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
}