Skip to content

Commit

Permalink
✅ Update test for device events
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaatttt authored and iujames committed Sep 17, 2024
1 parent 2245366 commit 349aed8
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions Tests/AppcuesKitTests/AppcuesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ class AppcuesTests: XCTestCase {
appcues.screen(title: "My test page") // not tracked
appcues.anonymous() // tracked 2 - session start + user
appcues.screen(title: "My test page") // tracked 1 - screen
appcues.reset() // stop tracking
appcues.reset() // tracked 1 - device unregister and stop tracking
appcues.screen(title: "My test page") // not tracked
appcues.identify(userID: "a-user-id") // tracked 2 - session start + user
appcues.screen(title: "My test page") // tracked 1 - screen

// Assert
XCTAssertEqual(6, subscriber.trackedUpdates)
XCTAssertEqual(7, subscriber.trackedUpdates)
}

func testAnonymousUserIdPrefix() throws {
Expand Down Expand Up @@ -255,6 +255,25 @@ class AppcuesTests: XCTestCase {
XCTAssertEqual(appcues.storage.pushToken, "736f6d652d746f6b656e")
}

func testSetPushTokenActiveSession() throws {
// Arrange
appcues.sessionID = UUID()
let token = "some-token".data(using: .utf8)
let eventExpectation = expectation(description: "Device event logged")
appcues.analyticsPublisher.onPublish = { trackingUpdate in
XCTAssertEqual(trackingUpdate.type, .event(name: Events.Device.deviceUpdated.rawValue, interactive: false))
XCTAssertNil(trackingUpdate.properties)
eventExpectation.fulfill()
}

// Act
appcues.setPushToken(token)

// Assert
waitForExpectations(timeout: 1)
XCTAssertEqual(appcues.storage.pushToken, "736f6d652d746f6b656e")
}

func testDidHandleURL() throws {
// Arrange
appcues.deepLinkHandler.onDidHandleURL = { url -> Bool in
Expand Down

0 comments on commit 349aed8

Please sign in to comment.