1
0
mirror of git://jb55.com/damus synced 2024-10-01 17:30:44 +00:00
damus/damusTests/DamusPurpleImpendingExpirationTests.swift

38 lines
2.2 KiB
Swift
Raw Normal View History

Add Damus Purple impending expiry notification support This commit adds Damus Purple expiry notification support. How it works: Whenever the app initiates or enters the foreground, it checks the user's account expiry, and calculates what notifications to display (It is functional, not imperative, to better match how the notifications view works) The notification handlers work the same as every other notification handler for Nostr events. However, local iOS notifications were not implemented to maintain these reminders more discreet. Current limitations: - Notifications cannot be dismissed - Notifications are dismissed only when Damus Purple is extended - After making a purchase, notifications are not dismissed right away - Bell icon with purple badge shows up on every app restart if user's account is expired Testing ------- Device: iPhone 13 Mini iOS: 17.3.1 Damus: This commit damus-api: d3801376fa204433661be6de8b7974f12b0ad25f Setup: - Local servers Setup - Debug endpoints enabled for changing expiry date on the fly Coverage: 1. Expired account 1. Starting the app on home screen shows bell icon with purple badge. PASS 2. 4 notifications appear on notifications view (7,3,1,0 days to expiry). PASS 3. Notifications appear in correct chronological order. PASS 4. Notifications look consistent in appearance. PASS 5. Expiry notifications' text size follows text size settings. PASS 6. Clicking on notification CTA takes user to account info page. PASS 2. Non-expired account (set expiry, restart app) 1. No expiry notifications, no bell icon. PASS 3. Expiry in 6 days (set expiry, restart app) 1. Starting the app on home screen shows bell icon with purple badge. PASS 2. Starting the app on the notification screen renders notifications the same way. PASS 3. Only one notification (7 days remaining) appears. PASS 4. Expiry in 2 days. PASS 5. General 1. Clicking bell icon clears away "new notifications" badge. PASS 2. Performance of notifications view does not seem affected. PASS 3. Performance of app on startup does not seem affected. PASS 6. IAP 1. Active IAP + expiry date in 2 days does not trigger reminder notification (Because it is auto-renewed). PASS Closes: https://github.com/damus-io/damus/issues/1973 Changelog-Added: Notification reminders for Damus Purple impending expiration Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2024-02-29 07:16:34 +00:00
//
// DamusPurpleImpendingExpirationTests.swift
// damusTests
//
// Created by Daniel DAquino on 2024-02-26.
//
import XCTest
@testable import damus
final class DamusPurpleImpendingExpirationTests : XCTestCase {
func testNotificationContentSetDoesNotAllowRepetition() {
var notification_contents: Set<DamusAppNotification.Content> = []
let expiry_date = UInt64(Date.now.timeIntervalSince1970)
let now = Date.now
let notification_1 = DamusAppNotification(content: .purple_impending_expiration(days_remaining: 3, expiry_date: expiry_date), timestamp: now)
notification_contents.insert(notification_1.content)
let notification_2 = DamusAppNotification(content: .purple_impending_expiration(days_remaining: 3, expiry_date: expiry_date), timestamp: now)
notification_contents.insert(notification_2.content)
let notification_3 = DamusAppNotification(content: .purple_impending_expiration(days_remaining: 2, expiry_date: expiry_date), timestamp: now)
notification_contents.insert(notification_3.content)
let notification_4 = DamusAppNotification(content: .purple_impending_expiration(days_remaining: 2, expiry_date: expiry_date), timestamp: now)
notification_contents.insert(notification_4.content)
let notification_5 = DamusAppNotification(content: .purple_impending_expiration(days_remaining: 1, expiry_date: expiry_date), timestamp: now)
notification_contents.insert(notification_5.content)
let notification_6 = DamusAppNotification(content: .purple_impending_expiration(days_remaining: 1, expiry_date: expiry_date), timestamp: now)
notification_contents.insert(notification_6.content)
XCTAssertEqual(notification_contents.count, 3)
XCTAssertTrue(notification_contents.contains(notification_1.content))
XCTAssertTrue(notification_contents.contains(notification_2.content))
XCTAssertTrue(notification_contents.contains(notification_3.content))
XCTAssertTrue(notification_contents.contains(notification_4.content))
XCTAssertTrue(notification_contents.contains(notification_5.content))
XCTAssertTrue(notification_contents.contains(notification_6.content))
}
}