From 3c90179d4b1c5d854c504aa1e7c660addac8c9f0 Mon Sep 17 00:00:00 2001 From: Jullian Mercier <31648126+jullianm@users.noreply.github.com> Date: Mon, 13 Jan 2025 17:15:12 +0100 Subject: [PATCH] generate notification for user connection (pending, accepted), add UTs --- .../UserConnectionNotificationBuilder.swift | 29 ++++++++++++++----- ...erConnectionNotificationBuilderTests.swift | 22 +++++++------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/WireDomain/Sources/WireDomain/Notifications/Builders/User/UserConnectionNotificationBuilder.swift b/WireDomain/Sources/WireDomain/Notifications/Builders/User/UserConnectionNotificationBuilder.swift index 93b2f595cc8..ad213c23e3d 100644 --- a/WireDomain/Sources/WireDomain/Notifications/Builders/User/UserConnectionNotificationBuilder.swift +++ b/WireDomain/Sources/WireDomain/Notifications/Builders/User/UserConnectionNotificationBuilder.swift @@ -52,11 +52,9 @@ struct UserConnectionNotificationBuilder: NotificationBuilder { case .joined: buildUserJoinNotification() case .pending: - // TODO: [WPB-11659] To implement - UNMutableNotificationContent() + buildConnectionRequestNotification(isPending: true) case .accepted: - // TODO: [WPB-11659] To implement - UNMutableNotificationContent() + buildConnectionRequestNotification(isPending: false) } } @@ -76,6 +74,22 @@ struct UserConnectionNotificationBuilder: NotificationBuilder { return content } + private func buildConnectionRequestNotification( + isPending: Bool + ) -> UNMutableNotificationContent { + let content = UNMutableNotificationContent() + + let body = NotificationBody.userConnection( + isPending ? .userWantsToConnect(username: context.username) : .usersConnected(username: context.username) + ) + + content.body = body.make() + content.categoryIdentifier = makeCategory() + content.sound = makeSound() + + return content + } + // MARK: - Helpers private func makeSound(type: NotificationSound = .default) -> UNNotificationSound { @@ -85,11 +99,10 @@ struct UserConnectionNotificationBuilder: NotificationBuilder { private func makeCategory() -> String { switch context.connectionStatus { - case .joined: + case .joined, .accepted: NotificationCategory.nonActionable.rawValue - case .pending, .accepted: - // TODO: [WPB-11659] To implement - "" + case .pending: + NotificationCategory.incomingConnectionRequest.rawValue } } diff --git a/WireDomain/Tests/WireDomainTests/Notifications/UserConnectionNotificationBuilderTests.swift b/WireDomain/Tests/WireDomainTests/Notifications/UserConnectionNotificationBuilderTests.swift index 6268301668a..d72b1f58ee4 100644 --- a/WireDomain/Tests/WireDomainTests/Notifications/UserConnectionNotificationBuilderTests.swift +++ b/WireDomain/Tests/WireDomainTests/Notifications/UserConnectionNotificationBuilderTests.swift @@ -16,22 +16,17 @@ // along with this program. If not, see http://www.gnu.org/licenses/. // -import WireAPISupport -import WireDataModel -import WireDataModelSupport -import WireTestingPackage import XCTest -@testable import WireAPI @testable import WireDomain -@testable import WireDomainSupport final class UserConnectionNotificationBuilderTests: XCTestCase { private var sut: UserConnectionNotificationBuilder! func testGenerateUserConnectionNotifications() async { - let connectionStatuses: [UserConnectionNotificationBuilder.ConnectionStatus] = [ - .joined + .joined, + .pending, + .accepted ] for connectionStatus in connectionStatuses { @@ -42,18 +37,21 @@ final class UserConnectionNotificationBuilderTests: XCTestCase { let notification = await sut.buildContent() + XCTAssertEqual(notification.title, "") + XCTAssertEqual(notification.sound, UNNotificationSound(named: .init("default"))) + switch connectionStatus { case .joined: - XCTAssertEqual(notification.title, "") XCTAssertEqual(notification.body, "\(Scaffolding.username) just joined Wire") - XCTAssertEqual(notification.sound, UNNotificationSound(named: .init("default"))) XCTAssertEqual(notification.categoryIdentifier, NotificationCategory.nonActionable.rawValue) case .pending: - fatalError() + XCTAssertEqual(notification.body, "\(Scaffolding.username) wants to connect") + XCTAssertEqual(notification.categoryIdentifier, NotificationCategory.incomingConnectionRequest.rawValue) case .accepted: - fatalError() + XCTAssertEqual(notification.body, "You and \(Scaffolding.username) are now connected") + XCTAssertEqual(notification.categoryIdentifier, NotificationCategory.nonActionable.rawValue) } } }