Skip to content

Commit

Permalink
Update unit tests for user id in no campaign reminders
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmeichigo committed Sep 12, 2024
1 parent 6e9da9d commit 6f58663
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ final class BlazeLocalNotificationSchedulerTests: XCTestCase {

let scenario = pushNotesManager.requestedLocalNotifications.first?.scenario
XCTAssertEqual(scenario, LocalNotification.Scenario.blazeNoCampaignReminder)
let userInfo = try XCTUnwrap(pushNotesManager.requestedLocalNotifications.first?.userInfo)
let siteIDFromNotification = try XCTUnwrap(userInfo["site_id"] as? Int64)
XCTAssertEqual(siteID, siteIDFromNotification)
}

func test_notification_is_not_scheduled_when_only_evergreen_campaign_exists_in_storage() async throws {
Expand Down Expand Up @@ -299,6 +302,36 @@ final class BlazeLocalNotificationSchedulerTests: XCTestCase {
// Then
XCTAssertTrue(pushNotesManager.canceledLocalNotificationScenarios.contains([LocalNotification.Scenario.blazeNoCampaignReminder]))
}

func test_notification_has_siteID_in_user_info() async throws {
// Given
let blazeEligibilityChecker = MockBlazeEligibilityChecker(isSiteEligible: true)
let campaignStartDate = Date.now.addingDays(1)
let fakeBlazeCampaign = BlazeCampaignListItem.fake().copy(siteID: siteID,
budgetCurrency: "USD",
isEvergreen: false,
durationDays: 15,
startTime: campaignStartDate)
let sut = DefaultBlazeLocalNotificationScheduler(siteID: siteID,
stores: stores,
storageManager: storageManager,
userDefaults: defaults,
pushNotesManager: pushNotesManager,
blazeEligibilityChecker: blazeEligibilityChecker)
await sut.scheduleNotifications()

// When
insertCampaigns([fakeBlazeCampaign])

// Then
waitUntil {
self.pushNotesManager.requestedLocalNotifications.isNotEmpty
}

let userInfo = try XCTUnwrap(pushNotesManager.requestedLocalNotifications.first?.userInfo)
let siteIDFromNotification = try XCTUnwrap(userInfo["site_id"] as? Int64)
XCTAssertEqual(siteID, siteIDFromNotification)
}
}

private extension BlazeLocalNotificationSchedulerTests {
Expand Down

0 comments on commit 6f58663

Please sign in to comment.