mirror of
https://github.com/block/buzz.git
synced 2026-10-31 22:41:12 +00:00
Test production notification sound handoff construction
Signed-off-by: Tom Brow <tomb@block.xyz>
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user