Test production notification sound handoff construction

Signed-off-by: Tom Brow <tomb@block.xyz>
This commit is contained in:
Tom Brow
2026-10-18 11:49:04 -07:00
parent 16801e881b
commit c1a5e92e8c
3 changed files with 17 additions and 8 deletions

View File

@@ -2,6 +2,16 @@ import UserNotifications
/// Applies the ordinary alert sound policy at the final service-extension handoff.
public enum BuzzNotificationSound {
/// Creates the service extension's final handoff with the incoming APNs sound policy.
public static func makeHandoff(
originalSound: UNNotificationSound?,
contentHandler: @escaping (UNNotificationContent) -> Void
) -> BuzzNotificationHandoff<UNNotificationContent> {
BuzzNotificationHandoff { content in
contentHandler(preparing(content, originalSound: originalSound))
}
}
/// Preserves the incoming APNs sound, or adds the default when no sound exists.
public static func preparing(
_ content: UNNotificationContent,

View File

@@ -39,8 +39,8 @@ struct BuzzNotificationSoundTests {
func `Final handoff applies sound to resolved and restricted content once`(allowed: Bool) {
var delivered: [UNNotificationContent] = []
let original = UNMutableNotificationContent()
let handoff = BuzzNotificationHandoff<UNNotificationContent> { content in
delivered.append(BuzzNotificationSound.preparing(content, originalSound: original.sound))
let handoff = BuzzNotificationSound.makeHandoff(originalSound: original.sound) { content in
delivered.append(content)
}
let resolved = UNMutableNotificationContent()
resolved.title = "Sender"
@@ -64,8 +64,8 @@ struct BuzzNotificationSoundTests {
@Test func `Expiration receives sound before a late resolution is ignored`() {
var delivered: [UNNotificationContent] = []
let handoff = BuzzNotificationHandoff<UNNotificationContent> { content in
delivered.append(BuzzNotificationSound.preparing(content, originalSound: nil))
let handoff = BuzzNotificationSound.makeHandoff(originalSound: nil) { content in
delivered.append(content)
}
for body in ["Reconnect to your relay now", "Resolved message"] {
let content = UNMutableNotificationContent()

View File

@@ -100,10 +100,9 @@ final class NotificationService: UNNotificationServiceExtension {
withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void
) {
resolvedScope = nil
let originalSound = request.content.sound
handoff = BuzzNotificationHandoff { content in
contentHandler(BuzzNotificationSound.preparing(content, originalSound: originalSound))
}
handoff = BuzzNotificationSound.makeHandoff(
originalSound: request.content.sound, contentHandler: contentHandler
)
restrictedFallbackContent = Self.restrictedFallback(from: request.content)
guard let content = request.content.mutableCopy() as? UNMutableNotificationContent else {
finish(request.content)