Skip to content

Commit

Permalink
fix: in-app missing event (customerio#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shahroz16 committed Feb 4, 2023
1 parent f0edfbc commit 43b3e97
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
12 changes: 5 additions & 7 deletions Sources/MessagingInApp/MessagingInAppImplementation.swift
Expand Up @@ -99,13 +99,11 @@ extension MessagingInAppImplementation: GistDelegate {
logger.debug("in-app action made. \(action), \(message.describeForLogs)")

// a close action does not count as a clicked action.
guard action != "gist://close" else {
return
}

if let deliveryId = getDeliveryId(from: message) {
// the state of the SDK does not change if adding this queue task isn't successful so ignore result
_ = queue.addTrackInAppDeliveryTask(deliveryId: deliveryId, event: .clicked)
if action != "gist://close" {
if let deliveryId = getDeliveryId(from: message) {
// the state of the SDK does not change if adding this queue task isn't successful so ignore result
_ = queue.addTrackInAppDeliveryTask(deliveryId: deliveryId, event: .clicked)
}
}

eventListener?.messageActionTaken(
Expand Down
21 changes: 21 additions & 0 deletions Tests/MessagingInApp/MessagingInAppImplementationTest.swift
Expand Up @@ -167,4 +167,25 @@ class MessagingInAppImplementationTest: UnitTest {
messagingInApp.action(message: givenGistMessage, currentRoute: .random, action: .random, name: .random)
XCTAssertEqual(eventListenerMock.messageActionTakenCallsCount, 2)
}

func test_eventListeners_givenCloseAction_expectListenerEvent() {
let givenGistMessage = Message.random
let expectedInAppMessage = InAppMessage(gistMessage: givenGistMessage)
let givenCurrentRoute = String.random
let givenAction = "gist://close"
let givenName = String.random

XCTAssertEqual(eventListenerMock.messageActionTakenCallsCount, 0)

messagingInApp.action(
message: givenGistMessage,
currentRoute: givenCurrentRoute,
action: givenAction,
name: givenName
)
XCTAssertEqual(eventListenerMock.messageActionTakenCallsCount, 1)
XCTAssertEqual(eventListenerMock.messageActionTakenReceivedArguments?.message, expectedInAppMessage)
XCTAssertEqual(eventListenerMock.messageActionTakenReceivedArguments?.actionValue, givenAction)
XCTAssertEqual(eventListenerMock.messageActionTakenReceivedArguments?.actionName, givenName)
}
}

0 comments on commit 43b3e97

Please sign in to comment.