Skip to content

Commit 6f58663

Browse files
committed
Update unit tests for user id in no campaign reminders
1 parent 6e9da9d commit 6f58663

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

WooCommerce/WooCommerceTests/ViewRelated/Blaze/BlazeLocalNotificationSchedulerTests.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ final class BlazeLocalNotificationSchedulerTests: XCTestCase {
183183

184184
let scenario = pushNotesManager.requestedLocalNotifications.first?.scenario
185185
XCTAssertEqual(scenario, LocalNotification.Scenario.blazeNoCampaignReminder)
186+
let userInfo = try XCTUnwrap(pushNotesManager.requestedLocalNotifications.first?.userInfo)
187+
let siteIDFromNotification = try XCTUnwrap(userInfo["site_id"] as? Int64)
188+
XCTAssertEqual(siteID, siteIDFromNotification)
186189
}
187190

188191
func test_notification_is_not_scheduled_when_only_evergreen_campaign_exists_in_storage() async throws {
@@ -299,6 +302,36 @@ final class BlazeLocalNotificationSchedulerTests: XCTestCase {
299302
// Then
300303
XCTAssertTrue(pushNotesManager.canceledLocalNotificationScenarios.contains([LocalNotification.Scenario.blazeNoCampaignReminder]))
301304
}
305+
306+
func test_notification_has_siteID_in_user_info() async throws {
307+
// Given
308+
let blazeEligibilityChecker = MockBlazeEligibilityChecker(isSiteEligible: true)
309+
let campaignStartDate = Date.now.addingDays(1)
310+
let fakeBlazeCampaign = BlazeCampaignListItem.fake().copy(siteID: siteID,
311+
budgetCurrency: "USD",
312+
isEvergreen: false,
313+
durationDays: 15,
314+
startTime: campaignStartDate)
315+
let sut = DefaultBlazeLocalNotificationScheduler(siteID: siteID,
316+
stores: stores,
317+
storageManager: storageManager,
318+
userDefaults: defaults,
319+
pushNotesManager: pushNotesManager,
320+
blazeEligibilityChecker: blazeEligibilityChecker)
321+
await sut.scheduleNotifications()
322+
323+
// When
324+
insertCampaigns([fakeBlazeCampaign])
325+
326+
// Then
327+
waitUntil {
328+
self.pushNotesManager.requestedLocalNotifications.isNotEmpty
329+
}
330+
331+
let userInfo = try XCTUnwrap(pushNotesManager.requestedLocalNotifications.first?.userInfo)
332+
let siteIDFromNotification = try XCTUnwrap(userInfo["site_id"] as? Int64)
333+
XCTAssertEqual(siteID, siteIDFromNotification)
334+
}
302335
}
303336

304337
private extension BlazeLocalNotificationSchedulerTests {

0 commit comments

Comments
 (0)