// // Copyright 2026 Element Creations Ltd. // // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial. // Please see LICENSE files in the repository root for full details. // @testable import ElementX import Foundation import Testing final class HealthChatExtendedProfileLoaderTests { private let service = ExtendedProfileServiceMock() @Test func showsProfileWithContent() async throws { service.profileForReturnValue = try .success(makeProfile(""" { "displayname": "Alice", "io.element.profile.business_tel": "+41 44 123 45 67" } """)) let loader = HealthChatExtendedProfileLoader(userID: "@alice:healthchat.ch", service: service) await loader.loadingTask?.value #expect(loader.profile?.businessTel == "+41 44 123 45 67") #expect(service.profileForReceivedUserID == "@alice:healthchat.ch") } @Test func hidesProfileWithoutHealthChatFields() async throws { service.profileForReturnValue = try .success(makeProfile(""" { "displayname": "Alice" } """)) let loader = HealthChatExtendedProfileLoader(userID: "@alice:healthchat.ch", service: service) await loader.loadingTask?.value #expect(loader.profile == nil) } @Test func hidesProfileOnFailure() async { service.profileForReturnValue = .failure(.networkFailure) let loader = HealthChatExtendedProfileLoader(userID: "@alice:healthchat.ch", service: service) await loader.loadingTask?.value #expect(loader.profile == nil) } private func makeProfile(_ json: String) throws -> ExtendedProfile { try JSONDecoder().decode(ExtendedProfile.self, from: Data(json.utf8)) } }