Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: generate notification connection request (pending, accepted) - WPB-11659 #2385

Open
wants to merge 1 commit into
base: refactor/generate-notification-connections
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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 {
Expand All @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
}
}
Expand Down
Loading