From c76db13d41ce6e811b08744d8e706e6d1b802a9d Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Tue, 8 Nov 2022 09:44:17 -0600 Subject: [PATCH 01/14] feat: add event listener for gist events --- .../autogenerated/AutoLenses.generated.swift | 55 ++---- .../AutoMockable.generated.swift | 1 - Sources/MessagingInApp/MessagingInApp.swift | 26 ++- .../Type/InAppEventListener.swift | 10 + .../MessagingInApp/Type/InAppMessage.swift | 18 ++ .../AutoMockable.generated.swift | 183 +++++++++++++++++- .../AutoMockable.generated.swift | 6 +- .../AutoMockable.generated.swift | 6 +- Tests/MessagingInApp/APITest.swift | 18 +- .../Extensions/GistExtensions.swift | 19 ++ Tests/MessagingInApp/MessagingInAppTest.swift | 92 ++++++++- 11 files changed, 367 insertions(+), 67 deletions(-) create mode 100644 Sources/MessagingInApp/Type/InAppEventListener.swift create mode 100644 Sources/MessagingInApp/Type/InAppMessage.swift create mode 100644 Tests/MessagingInApp/Extensions/GistExtensions.swift diff --git a/Sources/Common/autogenerated/AutoLenses.generated.swift b/Sources/Common/autogenerated/AutoLenses.generated.swift index 621eacdd3..552227416 100644 --- a/Sources/Common/autogenerated/AutoLenses.generated.swift +++ b/Sources/Common/autogenerated/AutoLenses.generated.swift @@ -65,45 +65,25 @@ extension QueueTask { static let storageIdLens = Lens( get: { $0.storageId }, set: { storageId, existing in - QueueTask( - storageId: storageId, - type: existing.type, - data: existing.data, - runResults: existing.runResults - ) + QueueTask(storageId: storageId, type: existing.type, data: existing.data, runResults: existing.runResults) } ) static let typeLens = Lens( get: { $0.type }, set: { type, existing in - QueueTask( - storageId: existing.storageId, - type: type, - data: existing.data, - runResults: existing.runResults - ) + QueueTask(storageId: existing.storageId, type: type, data: existing.data, runResults: existing.runResults) } ) static let dataLens = Lens( get: { $0.data }, set: { data, existing in - QueueTask( - storageId: existing.storageId, - type: existing.type, - data: data, - runResults: existing.runResults - ) + QueueTask(storageId: existing.storageId, type: existing.type, data: data, runResults: existing.runResults) } ) static let runResultsLens = Lens( get: { $0.runResults }, set: { runResults, existing in - QueueTask( - storageId: existing.storageId, - type: existing.type, - data: existing.data, - runResults: runResults - ) + QueueTask(storageId: existing.storageId, type: existing.type, data: existing.data, runResults: runResults) } ) @@ -132,12 +112,9 @@ extension QueueTaskMetadata { QueueTaskMetadata( taskPersistedId: taskPersistedId, taskType: existing.taskType, - groupStart: existing - .groupStart, - groupMember: existing - .groupMember, - createdAt: existing - .createdAt + groupStart: existing.groupStart, + groupMember: existing.groupMember, + createdAt: existing.createdAt ) } ) @@ -145,8 +122,7 @@ extension QueueTaskMetadata { get: { $0.taskType }, set: { taskType, existing in QueueTaskMetadata( - taskPersistedId: existing - .taskPersistedId, + taskPersistedId: existing.taskPersistedId, taskType: taskType, groupStart: existing.groupStart, groupMember: existing.groupMember, @@ -158,12 +134,10 @@ extension QueueTaskMetadata { get: { $0.groupStart }, set: { groupStart, existing in QueueTaskMetadata( - taskPersistedId: existing - .taskPersistedId, + taskPersistedId: existing.taskPersistedId, taskType: existing.taskType, groupStart: groupStart, - groupMember: existing - .groupMember, + groupMember: existing.groupMember, createdAt: existing.createdAt ) } @@ -172,11 +146,9 @@ extension QueueTaskMetadata { get: { $0.groupMember }, set: { groupMember, existing in QueueTaskMetadata( - taskPersistedId: existing - .taskPersistedId, + taskPersistedId: existing.taskPersistedId, taskType: existing.taskType, - groupStart: existing - .groupStart, + groupStart: existing.groupStart, groupMember: groupMember, createdAt: existing.createdAt ) @@ -186,8 +158,7 @@ extension QueueTaskMetadata { get: { $0.createdAt }, set: { createdAt, existing in QueueTaskMetadata( - taskPersistedId: existing - .taskPersistedId, + taskPersistedId: existing.taskPersistedId, taskType: existing.taskType, groupStart: existing.groupStart, groupMember: existing.groupMember, diff --git a/Sources/Common/autogenerated/AutoMockable.generated.swift b/Sources/Common/autogenerated/AutoMockable.generated.swift index b6b6b08a8..9656521cd 100644 --- a/Sources/Common/autogenerated/AutoMockable.generated.swift +++ b/Sources/Common/autogenerated/AutoMockable.generated.swift @@ -2375,7 +2375,6 @@ public class QueueMock: Queue, Mock { The closure has first priority to return a value for the mocked function. If the closure returns `nil`, then the mock will attempt to return the value for `addTaskReturnValue` */ - public var addTaskClosure: ((String, AnyEncodable, QueueTaskGroup?, [QueueTaskGroup]?) -> ModifyQueueResult)? /// Mocked function for `addTask(type: String, data: TaskData, groupStart: QueueTaskGroup?, diff --git a/Sources/MessagingInApp/MessagingInApp.swift b/Sources/MessagingInApp/MessagingInApp.swift index 88f7a9e23..c875a6fba 100644 --- a/Sources/MessagingInApp/MessagingInApp.swift +++ b/Sources/MessagingInApp/MessagingInApp.swift @@ -4,7 +4,7 @@ import Foundation import Gist public protocol MessagingInAppInstance: AutoMockable { - func initialize(organizationId: String) + func initialize(organizationId: String, eventListener: InAppEventListener?) } /** @@ -21,6 +21,8 @@ public class MessagingInApp: MessagingInAppInstance { diGraphOverride ?? DIGraph.getInstance(siteId: siteId) } + private var eventListener: InAppEventListener? + private var queue: Queue { diGraph.queue } @@ -38,9 +40,10 @@ public class MessagingInApp: MessagingInAppInstance { } // for testing - internal init(diGraph: DIGraph, siteId: String) { + internal init(diGraph: DIGraph, siteId: String, eventListener: InAppEventListener?) { self.diGraphOverride = diGraph self.siteId = siteId + self.eventListener = eventListener } private init() { @@ -57,8 +60,10 @@ public class MessagingInApp: MessagingInAppInstance { } } - public func initialize(organizationId: String) { - logger.debug("gist SDK being setup \(organizationId)") + public func initialize(organizationId: String, eventListener: InAppEventListener? = nil) { + logger.debug("In-app module being setup \(organizationId)") + + self.eventListener = eventListener inAppProvider.initialize(organizationId: organizationId, delegate: self) } @@ -100,14 +105,20 @@ extension MessagingInApp: GistDelegate { // the state of the SDK does not change if adding this queue task isn't successful so ignore result _ = queue.addTrackInAppDeliveryTask(deliveryId: deliveryId, event: .opened) } + + eventListener?.messageOpened(message: InAppMessage(gistMessage: message)) } public func messageDismissed(message: Message) { logger.debug("in-app message dismissed. \(message.describeForLogs)") + + eventListener?.messageDismissed(message: InAppMessage(gistMessage: message)) } public func messageError(message: Message) { logger.error("error with in-app message. \(message.describeForLogs)") + + eventListener?.errorWithMessage(message: InAppMessage(gistMessage: message)) } public func action(message: Message, currentRoute: String, action: String, name: String) { @@ -122,6 +133,13 @@ extension MessagingInApp: GistDelegate { // 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( + message: InAppMessage(gistMessage: message), + currentRoute: currentRoute, + action: action, + name: name + ) } private func getDeliveryId(from message: Message) -> String? { diff --git a/Sources/MessagingInApp/Type/InAppEventListener.swift b/Sources/MessagingInApp/Type/InAppEventListener.swift new file mode 100644 index 000000000..99f0bd018 --- /dev/null +++ b/Sources/MessagingInApp/Type/InAppEventListener.swift @@ -0,0 +1,10 @@ +import Common +import Foundation +import Gist + +public protocol InAppEventListener: AutoMockable { + func messageOpened(message: InAppMessage) + func messageDismissed(message: InAppMessage) + func errorWithMessage(message: InAppMessage) + func messageActionTaken(message: InAppMessage, currentRoute: String, action: String, name: String) +} diff --git a/Sources/MessagingInApp/Type/InAppMessage.swift b/Sources/MessagingInApp/Type/InAppMessage.swift new file mode 100644 index 000000000..e01838833 --- /dev/null +++ b/Sources/MessagingInApp/Type/InAppMessage.swift @@ -0,0 +1,18 @@ +import Foundation +import Gist + +typealias GistMessage = Message + +public struct InAppMessage: Equatable { + public let instanceId: String + public let messageId: String + public let deliveryId: String // (Currently taken from Gist's campaignId property) + + internal init(gistMessage: GistMessage) { + self.instanceId = gistMessage.instanceId + self.messageId = gistMessage.messageId + // The Gist SDK source code always populates the campaign-id. Having a nil campaignId is only common using the + // `public init()` for Message. + self.deliveryId = gistMessage.gistProperties.campaignId! + } +} diff --git a/Sources/MessagingInApp/autogenerated/AutoMockable.generated.swift b/Sources/MessagingInApp/autogenerated/AutoMockable.generated.swift index 0a5e068f2..efa05a27c 100644 --- a/Sources/MessagingInApp/autogenerated/AutoMockable.generated.swift +++ b/Sources/MessagingInApp/autogenerated/AutoMockable.generated.swift @@ -82,6 +82,168 @@ import Gist */ +/** + Class to easily create a mocked version of the `InAppEventListener` class. + This class is equipped with functions and properties ready for you to mock! + + Note: This file is automatically generated. This means the mocks should always be up-to-date and has a consistent API. + See the SDK documentation to learn the basics behind using the mock classes in the SDK. + */ +public class InAppEventListenerMock: InAppEventListener, Mock { + /// If *any* interactions done on mock. `true` if any method or property getter/setter called. + public var mockCalled: Bool = false // + + public init() { + Mocks.shared.add(mock: self) + } + + public func resetMock() { + messageOpenedCallsCount = 0 + messageOpenedReceivedArguments = nil + messageOpenedReceivedInvocations = [] + + mockCalled = false // do last as resetting properties above can make this true + messageDismissedCallsCount = 0 + messageDismissedReceivedArguments = nil + messageDismissedReceivedInvocations = [] + + mockCalled = false // do last as resetting properties above can make this true + errorWithMessageCallsCount = 0 + errorWithMessageReceivedArguments = nil + errorWithMessageReceivedInvocations = [] + + mockCalled = false // do last as resetting properties above can make this true + messageActionTakenCallsCount = 0 + messageActionTakenReceivedArguments = nil + messageActionTakenReceivedInvocations = [] + + mockCalled = false // do last as resetting properties above can make this true + } + + // MARK: - messageOpened + + /// Number of times the function was called. + public private(set) var messageOpenedCallsCount = 0 + /// `true` if the function was ever called. + public var messageOpenedCalled: Bool { + messageOpenedCallsCount > 0 + } + + /// The arguments from the *last* time the function was called. + public private(set) var messageOpenedReceivedArguments: InAppMessage? + /// Arguments from *all* of the times that the function was called. + public private(set) var messageOpenedReceivedInvocations: [InAppMessage] = [] + /** + Set closure to get called when function gets called. Great way to test logic or return a value for the function. + */ + public var messageOpenedClosure: ((InAppMessage) -> Void)? + + /// Mocked function for `messageOpened(message: InAppMessage)`. Your opportunity to return a mocked value and check + /// result of mock in test code. + public func messageOpened(message: InAppMessage) { + mockCalled = true + messageOpenedCallsCount += 1 + messageOpenedReceivedArguments = message + messageOpenedReceivedInvocations.append(message) + messageOpenedClosure?(message) + } + + // MARK: - messageDismissed + + /// Number of times the function was called. + public private(set) var messageDismissedCallsCount = 0 + /// `true` if the function was ever called. + public var messageDismissedCalled: Bool { + messageDismissedCallsCount > 0 + } + + /// The arguments from the *last* time the function was called. + public private(set) var messageDismissedReceivedArguments: InAppMessage? + /// Arguments from *all* of the times that the function was called. + public private(set) var messageDismissedReceivedInvocations: [InAppMessage] = [] + /** + Set closure to get called when function gets called. Great way to test logic or return a value for the function. + */ + public var messageDismissedClosure: ((InAppMessage) -> Void)? + + /// Mocked function for `messageDismissed(message: InAppMessage)`. Your opportunity to return a mocked value and + /// check result of mock in test code. + public func messageDismissed(message: InAppMessage) { + mockCalled = true + messageDismissedCallsCount += 1 + messageDismissedReceivedArguments = message + messageDismissedReceivedInvocations.append(message) + messageDismissedClosure?(message) + } + + // MARK: - errorWithMessage + + /// Number of times the function was called. + public private(set) var errorWithMessageCallsCount = 0 + /// `true` if the function was ever called. + public var errorWithMessageCalled: Bool { + errorWithMessageCallsCount > 0 + } + + /// The arguments from the *last* time the function was called. + public private(set) var errorWithMessageReceivedArguments: InAppMessage? + /// Arguments from *all* of the times that the function was called. + public private(set) var errorWithMessageReceivedInvocations: [InAppMessage] = [] + /** + Set closure to get called when function gets called. Great way to test logic or return a value for the function. + */ + public var errorWithMessageClosure: ((InAppMessage) -> Void)? + + /// Mocked function for `errorWithMessage(message: InAppMessage)`. Your opportunity to return a mocked value and + /// check result of mock in test code. + public func errorWithMessage(message: InAppMessage) { + mockCalled = true + errorWithMessageCallsCount += 1 + errorWithMessageReceivedArguments = message + errorWithMessageReceivedInvocations.append(message) + errorWithMessageClosure?(message) + } + + // MARK: - messageActionTaken + + /// Number of times the function was called. + public private(set) var messageActionTakenCallsCount = 0 + /// `true` if the function was ever called. + public var messageActionTakenCalled: Bool { + messageActionTakenCallsCount > 0 + } + + /// The arguments from the *last* time the function was called. + public private(set) var messageActionTakenReceivedArguments: ( + message: InAppMessage, + currentRoute: String, + action: String, + name: String + )? + /// Arguments from *all* of the times that the function was called. + public private(set) var messageActionTakenReceivedInvocations: [( + message: InAppMessage, + currentRoute: String, + action: String, + name: String + )] = [] + /** + Set closure to get called when function gets called. Great way to test logic or return a value for the function. + */ + public var messageActionTakenClosure: ((InAppMessage, String, String, String) -> Void)? + + /// Mocked function for `messageActionTaken(message: InAppMessage, currentRoute: String, action: String, name: + /// String)`. Your opportunity to return a mocked value and check result of mock in test code. + public func messageActionTaken(message: InAppMessage, currentRoute: String, action: String, name: String) { + mockCalled = true + messageActionTakenCallsCount += 1 + messageActionTakenReceivedArguments = (message: message, currentRoute: currentRoute, action: action, name: name) + messageActionTakenReceivedInvocations + .append((message: message, currentRoute: currentRoute, action: action, name: name)) + messageActionTakenClosure?(message, currentRoute, action, name) + } +} + /** Class to easily create a mocked version of the `InAppProvider` class. This class is equipped with functions and properties ready for you to mock! @@ -258,21 +420,24 @@ public class MessagingInAppInstanceMock: MessagingInAppInstance, Mock { } /// The arguments from the *last* time the function was called. - public private(set) var initializeReceivedArguments: String? + public private(set) var initializeReceivedArguments: (organizationId: String, eventListener: InAppEventListener?)? /// Arguments from *all* of the times that the function was called. - public private(set) var initializeReceivedInvocations: [String] = [] + public private(set) var initializeReceivedInvocations: [( + organizationId: String, + eventListener: InAppEventListener? + )] = [] /** Set closure to get called when function gets called. Great way to test logic or return a value for the function. */ - public var initializeClosure: ((String) -> Void)? + public var initializeClosure: ((String, InAppEventListener?) -> Void)? - /// Mocked function for `initialize(organizationId: String)`. Your opportunity to return a mocked value and check - /// result of mock in test code. - public func initialize(organizationId: String) { + /// Mocked function for `initialize(organizationId: String, eventListener: InAppEventListener?)`. Your opportunity + /// to return a mocked value and check result of mock in test code. + public func initialize(organizationId: String, eventListener: InAppEventListener?) { mockCalled = true initializeCallsCount += 1 - initializeReceivedArguments = organizationId - initializeReceivedInvocations.append(organizationId) - initializeClosure?(organizationId) + initializeReceivedArguments = (organizationId: organizationId, eventListener: eventListener) + initializeReceivedInvocations.append((organizationId: organizationId, eventListener: eventListener)) + initializeClosure?(organizationId, eventListener) } } diff --git a/Sources/MessagingPushAPN/autogenerated/AutoMockable.generated.swift b/Sources/MessagingPushAPN/autogenerated/AutoMockable.generated.swift index 83883a220..f14011ebe 100644 --- a/Sources/MessagingPushAPN/autogenerated/AutoMockable.generated.swift +++ b/Sources/MessagingPushAPN/autogenerated/AutoMockable.generated.swift @@ -290,14 +290,12 @@ public class MessagingPushAPNInstanceMock: MessagingPushAPNInstance, Mock { /// The arguments from the *last* time the function was called. public private(set) var didReceiveNotificationRequestReceivedArguments: ( request: UNNotificationRequest, - contentHandler: (UNNotificationContent) - -> Void + contentHandler: (UNNotificationContent) -> Void )? /// Arguments from *all* of the times that the function was called. public private(set) var didReceiveNotificationRequestReceivedInvocations: [( request: UNNotificationRequest, - contentHandler: (UNNotificationContent) - -> Void + contentHandler: (UNNotificationContent) -> Void )] = [] /// Value to return from the mocked function. public var didReceiveNotificationRequestReturnValue: Bool! diff --git a/Sources/MessagingPushFCM/autogenerated/AutoMockable.generated.swift b/Sources/MessagingPushFCM/autogenerated/AutoMockable.generated.swift index 5026a06f4..c9e6a2f60 100644 --- a/Sources/MessagingPushFCM/autogenerated/AutoMockable.generated.swift +++ b/Sources/MessagingPushFCM/autogenerated/AutoMockable.generated.swift @@ -286,14 +286,12 @@ public class MessagingPushFCMInstanceMock: MessagingPushFCMInstance, Mock { /// The arguments from the *last* time the function was called. public private(set) var didReceiveNotificationRequestReceivedArguments: ( request: UNNotificationRequest, - contentHandler: (UNNotificationContent) - -> Void + contentHandler: (UNNotificationContent) -> Void )? /// Arguments from *all* of the times that the function was called. public private(set) var didReceiveNotificationRequestReceivedInvocations: [( request: UNNotificationRequest, - contentHandler: (UNNotificationContent) - -> Void + contentHandler: (UNNotificationContent) -> Void )] = [] /// Value to return from the mocked function. public var didReceiveNotificationRequestReturnValue: Bool! diff --git a/Tests/MessagingInApp/APITest.swift b/Tests/MessagingInApp/APITest.swift index 27d639fe9..28af5e971 100644 --- a/Tests/MessagingInApp/APITest.swift +++ b/Tests/MessagingInApp/APITest.swift @@ -19,6 +19,22 @@ class MessagingInAppAPITest: UnitTest { try skipRunningTest() MessagingInApp.shared.initialize(organizationId: "") - mock.initialize(organizationId: "") + MessagingInApp.shared.initialize(organizationId: "", eventListener: self) + mock.initialize(organizationId: "", eventListener: self) } } + +extension MessagingInAppAPITest: InAppEventListener { + func messageOpened(message: InAppMessage) { + // make sure all properties of InAppMessage are accessible + _ = message.instanceId + _ = message.messageId + _ = message.deliveryId + } + + func messageDismissed(message: InAppMessage) {} + + func errorWithMessage(message: InAppMessage) {} + + func messageActionTaken(message: InAppMessage, currentRoute: String, action: String, name: String) {} +} diff --git a/Tests/MessagingInApp/Extensions/GistExtensions.swift b/Tests/MessagingInApp/Extensions/GistExtensions.swift new file mode 100644 index 000000000..cc851cf46 --- /dev/null +++ b/Tests/MessagingInApp/Extensions/GistExtensions.swift @@ -0,0 +1,19 @@ +@testable import CioMessagingInApp +import Foundation +@testable import Gist + +extension Message { + convenience init(messageId: String, campaignId: String) { + let gistProperties = [ + "gist": [ + "campaignId": campaignId + ] + ] + + self.init(messageId: messageId, properties: gistProperties) + } + + static var random: Message { + Message(messageId: .random, campaignId: .random) + } +} diff --git a/Tests/MessagingInApp/MessagingInAppTest.swift b/Tests/MessagingInApp/MessagingInAppTest.swift index 31f673ec4..238102597 100644 --- a/Tests/MessagingInApp/MessagingInAppTest.swift +++ b/Tests/MessagingInApp/MessagingInAppTest.swift @@ -1,7 +1,8 @@ @testable import CioMessagingInApp @testable import CioTracking +@testable import Common import Foundation -import Gist +@testable import Gist import SharedTests import XCTest @@ -9,13 +10,16 @@ class MessagingInAppTest: UnitTest { private var messagingInApp: MessagingInApp! private let inAppProviderMock = InAppProviderMock() + private let eventListenerMock = InAppEventListenerMock() + private let queueMock = QueueMock() override func setUp() { super.setUp() diGraph.override(value: inAppProviderMock, forType: InAppProvider.self) + diGraph.override(value: queueMock, forType: Queue.self) - messagingInApp = MessagingInApp(diGraph: diGraph, siteId: testSiteId) + messagingInApp = MessagingInApp(diGraph: diGraph, siteId: testSiteId, eventListener: eventListenerMock) } // MARK: initialize @@ -55,4 +59,88 @@ class MessagingInAppTest: UnitTest { XCTAssertEqual(inAppProviderMock.setRouteCallsCount, 1) XCTAssertEqual(inAppProviderMock.setRouteReceivedArguments, given) } + + // MARK: event listeners + + func test_eventListeners_expectCallListenerWithData() { + let givenGistMessage = Message.random + let expectedInAppMessage = InAppMessage(gistMessage: givenGistMessage) + + queueMock.addTrackInAppDeliveryTaskReturnValue = ModifyQueueResult( + success: true, + QueueStatus(queueId: .random, numTasksInQueue: 1) + ) + + // Message opened + XCTAssertFalse(eventListenerMock.messageOpenedCalled) + messagingInApp.messageShown(message: givenGistMessage) + XCTAssertEqual(eventListenerMock.messageOpenedCallsCount, 1) + XCTAssertEqual(eventListenerMock.messageOpenedReceivedArguments, expectedInAppMessage) + + // message dismissed + XCTAssertFalse(eventListenerMock.messageDismissedCalled) + messagingInApp.messageDismissed(message: givenGistMessage) + XCTAssertEqual(eventListenerMock.messageDismissedCallsCount, 1) + XCTAssertEqual(eventListenerMock.messageDismissedReceivedArguments, expectedInAppMessage) + + // error with message + XCTAssertFalse(eventListenerMock.errorWithMessageCalled) + messagingInApp.messageError(message: givenGistMessage) + XCTAssertEqual(eventListenerMock.errorWithMessageCallsCount, 1) + XCTAssertEqual(eventListenerMock.errorWithMessageReceivedArguments, expectedInAppMessage) + + // message action taken + XCTAssertFalse(eventListenerMock.messageActionTakenCalled) + let givenCurrentRoute = String.random + let givenAction = String.random + let givenName = String.random + messagingInApp.action( + message: givenGistMessage, + currentRoute: givenCurrentRoute, + action: givenAction, + name: givenName + ) + XCTAssertEqual(eventListenerMock.messageActionTakenCallsCount, 1) + XCTAssertEqual(eventListenerMock.messageActionTakenReceivedArguments?.message, expectedInAppMessage) + XCTAssertEqual(eventListenerMock.messageActionTakenReceivedArguments?.currentRoute, givenCurrentRoute) + XCTAssertEqual(eventListenerMock.messageActionTakenReceivedArguments?.action, givenAction) + XCTAssertEqual(eventListenerMock.messageActionTakenReceivedArguments?.name, givenName) + } + + func test_eventListeners_expectCallListenerForEachEvent() { + let givenGistMessage = Message.random + + queueMock.addTrackInAppDeliveryTaskReturnValue = ModifyQueueResult( + success: true, + QueueStatus(queueId: .random, numTasksInQueue: 1) + ) + + // Message opened + XCTAssertEqual(eventListenerMock.messageOpenedCallsCount, 0) + messagingInApp.messageShown(message: givenGistMessage) + XCTAssertEqual(eventListenerMock.messageOpenedCallsCount, 1) + messagingInApp.messageShown(message: givenGistMessage) + XCTAssertEqual(eventListenerMock.messageOpenedCallsCount, 2) + + // message dismissed + XCTAssertEqual(eventListenerMock.messageDismissedCallsCount, 0) + messagingInApp.messageDismissed(message: givenGistMessage) + XCTAssertEqual(eventListenerMock.messageDismissedCallsCount, 1) + messagingInApp.messageDismissed(message: givenGistMessage) + XCTAssertEqual(eventListenerMock.messageDismissedCallsCount, 2) + + // error with message + XCTAssertEqual(eventListenerMock.errorWithMessageCallsCount, 0) + messagingInApp.messageError(message: givenGistMessage) + XCTAssertEqual(eventListenerMock.errorWithMessageCallsCount, 1) + messagingInApp.messageError(message: givenGistMessage) + XCTAssertEqual(eventListenerMock.errorWithMessageCallsCount, 2) + + // message action taken + XCTAssertEqual(eventListenerMock.messageActionTakenCallsCount, 0) + messagingInApp.action(message: givenGistMessage, currentRoute: .random, action: .random, name: .random) + XCTAssertEqual(eventListenerMock.messageActionTakenCallsCount, 1) + messagingInApp.action(message: givenGistMessage, currentRoute: .random, action: .random, name: .random) + XCTAssertEqual(eventListenerMock.messageActionTakenCallsCount, 2) + } } From 369e74092d6ea4ef550ebb2c3d8994c5f21fa264 Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Wed, 9 Nov 2022 08:03:05 -0600 Subject: [PATCH 02/14] rename messageOpened to messageShown --- Sources/MessagingInApp/MessagingInApp.swift | 2 +- .../Type/InAppEventListener.swift | 2 +- .../AutoMockable.generated.swift | 32 +++++++++---------- Tests/MessagingInApp/APITest.swift | 2 +- Tests/MessagingInApp/MessagingInAppTest.swift | 12 +++---- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Sources/MessagingInApp/MessagingInApp.swift b/Sources/MessagingInApp/MessagingInApp.swift index c875a6fba..f43c465a5 100644 --- a/Sources/MessagingInApp/MessagingInApp.swift +++ b/Sources/MessagingInApp/MessagingInApp.swift @@ -106,7 +106,7 @@ extension MessagingInApp: GistDelegate { _ = queue.addTrackInAppDeliveryTask(deliveryId: deliveryId, event: .opened) } - eventListener?.messageOpened(message: InAppMessage(gistMessage: message)) + eventListener?.messageShown(message: InAppMessage(gistMessage: message)) } public func messageDismissed(message: Message) { diff --git a/Sources/MessagingInApp/Type/InAppEventListener.swift b/Sources/MessagingInApp/Type/InAppEventListener.swift index 99f0bd018..c66cdb000 100644 --- a/Sources/MessagingInApp/Type/InAppEventListener.swift +++ b/Sources/MessagingInApp/Type/InAppEventListener.swift @@ -3,7 +3,7 @@ import Foundation import Gist public protocol InAppEventListener: AutoMockable { - func messageOpened(message: InAppMessage) + func messageShown(message: InAppMessage) func messageDismissed(message: InAppMessage) func errorWithMessage(message: InAppMessage) func messageActionTaken(message: InAppMessage, currentRoute: String, action: String, name: String) diff --git a/Sources/MessagingInApp/autogenerated/AutoMockable.generated.swift b/Sources/MessagingInApp/autogenerated/AutoMockable.generated.swift index efa05a27c..8983e1a13 100644 --- a/Sources/MessagingInApp/autogenerated/AutoMockable.generated.swift +++ b/Sources/MessagingInApp/autogenerated/AutoMockable.generated.swift @@ -98,9 +98,9 @@ public class InAppEventListenerMock: InAppEventListener, Mock { } public func resetMock() { - messageOpenedCallsCount = 0 - messageOpenedReceivedArguments = nil - messageOpenedReceivedInvocations = [] + messageShownCallsCount = 0 + messageShownReceivedArguments = nil + messageShownReceivedInvocations = [] mockCalled = false // do last as resetting properties above can make this true messageDismissedCallsCount = 0 @@ -120,32 +120,32 @@ public class InAppEventListenerMock: InAppEventListener, Mock { mockCalled = false // do last as resetting properties above can make this true } - // MARK: - messageOpened + // MARK: - messageShown /// Number of times the function was called. - public private(set) var messageOpenedCallsCount = 0 + public private(set) var messageShownCallsCount = 0 /// `true` if the function was ever called. - public var messageOpenedCalled: Bool { - messageOpenedCallsCount > 0 + public var messageShownCalled: Bool { + messageShownCallsCount > 0 } /// The arguments from the *last* time the function was called. - public private(set) var messageOpenedReceivedArguments: InAppMessage? + public private(set) var messageShownReceivedArguments: InAppMessage? /// Arguments from *all* of the times that the function was called. - public private(set) var messageOpenedReceivedInvocations: [InAppMessage] = [] + public private(set) var messageShownReceivedInvocations: [InAppMessage] = [] /** Set closure to get called when function gets called. Great way to test logic or return a value for the function. */ - public var messageOpenedClosure: ((InAppMessage) -> Void)? + public var messageShownClosure: ((InAppMessage) -> Void)? - /// Mocked function for `messageOpened(message: InAppMessage)`. Your opportunity to return a mocked value and check + /// Mocked function for `messageShown(message: InAppMessage)`. Your opportunity to return a mocked value and check /// result of mock in test code. - public func messageOpened(message: InAppMessage) { + public func messageShown(message: InAppMessage) { mockCalled = true - messageOpenedCallsCount += 1 - messageOpenedReceivedArguments = message - messageOpenedReceivedInvocations.append(message) - messageOpenedClosure?(message) + messageShownCallsCount += 1 + messageShownReceivedArguments = message + messageShownReceivedInvocations.append(message) + messageShownClosure?(message) } // MARK: - messageDismissed diff --git a/Tests/MessagingInApp/APITest.swift b/Tests/MessagingInApp/APITest.swift index 28af5e971..35f21f310 100644 --- a/Tests/MessagingInApp/APITest.swift +++ b/Tests/MessagingInApp/APITest.swift @@ -25,7 +25,7 @@ class MessagingInAppAPITest: UnitTest { } extension MessagingInAppAPITest: InAppEventListener { - func messageOpened(message: InAppMessage) { + func messageShown(message: InAppMessage) { // make sure all properties of InAppMessage are accessible _ = message.instanceId _ = message.messageId diff --git a/Tests/MessagingInApp/MessagingInAppTest.swift b/Tests/MessagingInApp/MessagingInAppTest.swift index 238102597..da35ab310 100644 --- a/Tests/MessagingInApp/MessagingInAppTest.swift +++ b/Tests/MessagingInApp/MessagingInAppTest.swift @@ -72,10 +72,10 @@ class MessagingInAppTest: UnitTest { ) // Message opened - XCTAssertFalse(eventListenerMock.messageOpenedCalled) + XCTAssertFalse(eventListenerMock.messageShownCalled) messagingInApp.messageShown(message: givenGistMessage) - XCTAssertEqual(eventListenerMock.messageOpenedCallsCount, 1) - XCTAssertEqual(eventListenerMock.messageOpenedReceivedArguments, expectedInAppMessage) + XCTAssertEqual(eventListenerMock.messageShownCallsCount, 1) + XCTAssertEqual(eventListenerMock.messageShownReceivedArguments, expectedInAppMessage) // message dismissed XCTAssertFalse(eventListenerMock.messageDismissedCalled) @@ -116,11 +116,11 @@ class MessagingInAppTest: UnitTest { ) // Message opened - XCTAssertEqual(eventListenerMock.messageOpenedCallsCount, 0) + XCTAssertEqual(eventListenerMock.messageShownCallsCount, 0) messagingInApp.messageShown(message: givenGistMessage) - XCTAssertEqual(eventListenerMock.messageOpenedCallsCount, 1) + XCTAssertEqual(eventListenerMock.messageShownCallsCount, 1) messagingInApp.messageShown(message: givenGistMessage) - XCTAssertEqual(eventListenerMock.messageOpenedCallsCount, 2) + XCTAssertEqual(eventListenerMock.messageShownCallsCount, 2) // message dismissed XCTAssertEqual(eventListenerMock.messageDismissedCallsCount, 0) From 51f9f3fdaa0ec0dc8078994d00dd1147aaf0e323 Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Thu, 10 Nov 2022 13:17:55 -0600 Subject: [PATCH 03/14] add back initialize without event listener --- Sources/MessagingInApp/MessagingInApp.swift | 12 +++- .../AutoMockable.generated.swift | 59 +++++++++++++++---- Tests/MessagingInApp/APITest.swift | 1 + 3 files changed, 58 insertions(+), 14 deletions(-) diff --git a/Sources/MessagingInApp/MessagingInApp.swift b/Sources/MessagingInApp/MessagingInApp.swift index f43c465a5..a995596ec 100644 --- a/Sources/MessagingInApp/MessagingInApp.swift +++ b/Sources/MessagingInApp/MessagingInApp.swift @@ -4,7 +4,9 @@ import Foundation import Gist public protocol MessagingInAppInstance: AutoMockable { - func initialize(organizationId: String, eventListener: InAppEventListener?) + func initialize(organizationId: String) + // sourcery:Name=initializeEventListener + func initialize(organizationId: String, eventListener: InAppEventListener) } /** @@ -60,12 +62,16 @@ public class MessagingInApp: MessagingInAppInstance { } } - public func initialize(organizationId: String, eventListener: InAppEventListener? = nil) { + public func initialize(organizationId: String) { logger.debug("In-app module being setup \(organizationId)") + inAppProvider.initialize(organizationId: organizationId, delegate: self) + } + + public func initialize(organizationId: String, eventListener: InAppEventListener) { self.eventListener = eventListener - inAppProvider.initialize(organizationId: organizationId, delegate: self) + initialize(organizationId: organizationId) } } diff --git a/Sources/MessagingInApp/autogenerated/AutoMockable.generated.swift b/Sources/MessagingInApp/autogenerated/AutoMockable.generated.swift index 8983e1a13..4bf8aa3ff 100644 --- a/Sources/MessagingInApp/autogenerated/AutoMockable.generated.swift +++ b/Sources/MessagingInApp/autogenerated/AutoMockable.generated.swift @@ -407,6 +407,11 @@ public class MessagingInAppInstanceMock: MessagingInAppInstance, Mock { initializeReceivedArguments = nil initializeReceivedInvocations = [] + mockCalled = false // do last as resetting properties above can make this true + initializeEventListenerCallsCount = 0 + initializeEventListenerReceivedArguments = nil + initializeEventListenerReceivedInvocations = [] + mockCalled = false // do last as resetting properties above can make this true } @@ -420,24 +425,56 @@ public class MessagingInAppInstanceMock: MessagingInAppInstance, Mock { } /// The arguments from the *last* time the function was called. - public private(set) var initializeReceivedArguments: (organizationId: String, eventListener: InAppEventListener?)? + public private(set) var initializeReceivedArguments: String? + /// Arguments from *all* of the times that the function was called. + public private(set) var initializeReceivedInvocations: [String] = [] + /** + Set closure to get called when function gets called. Great way to test logic or return a value for the function. + */ + public var initializeClosure: ((String) -> Void)? + + /// Mocked function for `initialize(organizationId: String)`. Your opportunity to return a mocked value and check + /// result of mock in test code. + public func initialize(organizationId: String) { + mockCalled = true + initializeCallsCount += 1 + initializeReceivedArguments = organizationId + initializeReceivedInvocations.append(organizationId) + initializeClosure?(organizationId) + } + + // MARK: - initialize + + /// Number of times the function was called. + public private(set) var initializeEventListenerCallsCount = 0 + /// `true` if the function was ever called. + public var initializeEventListenerCalled: Bool { + initializeEventListenerCallsCount > 0 + } + + /// The arguments from the *last* time the function was called. + public private(set) var initializeEventListenerReceivedArguments: ( + organizationId: String, + eventListener: InAppEventListener + )? /// Arguments from *all* of the times that the function was called. - public private(set) var initializeReceivedInvocations: [( + public private(set) var initializeEventListenerReceivedInvocations: [( organizationId: String, - eventListener: InAppEventListener? + eventListener: InAppEventListener )] = [] /** Set closure to get called when function gets called. Great way to test logic or return a value for the function. */ - public var initializeClosure: ((String, InAppEventListener?) -> Void)? + public var initializeEventListenerClosure: ((String, InAppEventListener) -> Void)? - /// Mocked function for `initialize(organizationId: String, eventListener: InAppEventListener?)`. Your opportunity - /// to return a mocked value and check result of mock in test code. - public func initialize(organizationId: String, eventListener: InAppEventListener?) { + /// Mocked function for `initialize(organizationId: String, eventListener: InAppEventListener)`. Your opportunity to + /// return a mocked value and check result of mock in test code. + public func initialize(organizationId: String, eventListener: InAppEventListener) { mockCalled = true - initializeCallsCount += 1 - initializeReceivedArguments = (organizationId: organizationId, eventListener: eventListener) - initializeReceivedInvocations.append((organizationId: organizationId, eventListener: eventListener)) - initializeClosure?(organizationId, eventListener) + initializeEventListenerCallsCount += 1 + initializeEventListenerReceivedArguments = (organizationId: organizationId, eventListener: eventListener) + initializeEventListenerReceivedInvocations + .append((organizationId: organizationId, eventListener: eventListener)) + initializeEventListenerClosure?(organizationId, eventListener) } } diff --git a/Tests/MessagingInApp/APITest.swift b/Tests/MessagingInApp/APITest.swift index 35f21f310..a6dd0b8ac 100644 --- a/Tests/MessagingInApp/APITest.swift +++ b/Tests/MessagingInApp/APITest.swift @@ -20,6 +20,7 @@ class MessagingInAppAPITest: UnitTest { MessagingInApp.shared.initialize(organizationId: "") MessagingInApp.shared.initialize(organizationId: "", eventListener: self) + mock.initialize(organizationId: "") mock.initialize(organizationId: "", eventListener: self) } } From 5ef489a2153740006ce78cec9a6c310bd2235e52 Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Tue, 15 Nov 2022 23:14:35 -0600 Subject: [PATCH 04/14] deliveryid can be null for in-app message --- Sources/MessagingInApp/Type/InAppMessage.swift | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Sources/MessagingInApp/Type/InAppMessage.swift b/Sources/MessagingInApp/Type/InAppMessage.swift index e01838833..8a08d011b 100644 --- a/Sources/MessagingInApp/Type/InAppMessage.swift +++ b/Sources/MessagingInApp/Type/InAppMessage.swift @@ -6,13 +6,12 @@ typealias GistMessage = Message public struct InAppMessage: Equatable { public let instanceId: String public let messageId: String - public let deliveryId: String // (Currently taken from Gist's campaignId property) + public let deliveryId: String? // (Currently taken from Gist's campaignId property). Can be nil when sending test + // in-app messages internal init(gistMessage: GistMessage) { self.instanceId = gistMessage.instanceId self.messageId = gistMessage.messageId - // The Gist SDK source code always populates the campaign-id. Having a nil campaignId is only common using the - // `public init()` for Message. - self.deliveryId = gistMessage.gistProperties.campaignId! + self.deliveryId = gistMessage.gistProperties.campaignId } } From c12fc1ae423b9ee418a9f051f496e2bb0777c0c6 Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Tue, 15 Nov 2022 23:33:41 -0600 Subject: [PATCH 05/14] attempt to fix lint on ci --- .github/workflows/lint.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 52ac21132..ce0085907 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -4,10 +4,10 @@ on: [pull_request] jobs: SwiftLint: - runs-on: ubuntu-latest + runs-on: macos-latest steps: - uses: actions/checkout@v2 - - name: Lint via SwiftLint - uses: norio-nomura/action-swiftlint@3.2.1 - with: - args: --strict \ No newline at end of file + - name: Install swiftlint + run: brew install swiftlint + - name: Run swiftlint. Fail if any errors. + run: make lint \ No newline at end of file From b48ceee78dec71d5ce2996a60329a4c8c4561645 Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Tue, 15 Nov 2022 23:46:06 -0600 Subject: [PATCH 06/14] fix ci lint --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ce0085907..4d2167cce 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -8,6 +8,6 @@ jobs: steps: - uses: actions/checkout@v2 - name: Install swiftlint - run: brew install swiftlint + run: brew install swiftlint || brew upgrade swiftlint - name: Run swiftlint. Fail if any errors. run: make lint \ No newline at end of file From 50c42838b0914ea9bae22bdff788aae70e5260e3 Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Wed, 18 Jan 2023 09:29:19 -0600 Subject: [PATCH 07/14] remove parameters from listener not needed --- .../AutoDependencyInjection.generated.swift | 69 +--- .../autogenerated/AutoLenses.generated.swift | 80 +---- .../AutoMockable.generated.swift | 296 +++++------------- .../MessagingInAppImplementation.swift | 1 - .../Type/InAppEventListener.swift | 2 +- .../MessagingInApp/Type/InAppMessage.swift | 2 - .../AutoMockable.generated.swift | 68 ++-- .../AutoMockable.generated.swift | 104 ++---- .../AutoMockable.generated.swift | 56 +--- .../AutoMockable.generated.swift | 48 +-- .../AutoDependencyInjection.generated.swift | 8 +- .../AutoMockable.generated.swift | 39 +-- Tests/MessagingInApp/APITest.swift | 3 +- .../MessagingInAppImplementationTest.swift | 1 - 14 files changed, 181 insertions(+), 596 deletions(-) diff --git a/Sources/Common/autogenerated/AutoDependencyInjection.generated.swift b/Sources/Common/autogenerated/AutoDependencyInjection.generated.swift index 43d2a6873..9f254311d 100644 --- a/Sources/Common/autogenerated/AutoDependencyInjection.generated.swift +++ b/Sources/Common/autogenerated/AutoDependencyInjection.generated.swift @@ -148,18 +148,7 @@ extension DIGraph { } private var newHttpClient: HttpClient { - CIOHttpClient( - siteId: siteId, - apiKey: apiKey, - sdkConfig: sdkConfig, - jsonAdapter: jsonAdapter, - httpRequestRunner: httpRequestRunner, - globalDataStore: globalDataStore, - logger: logger, - timer: simpleTimer, - retryPolicy: httpRetryPolicy, - userAgentUtil: userAgentUtil - ) + CIOHttpClient(siteId: siteId, apiKey: apiKey, sdkConfig: sdkConfig, jsonAdapter: jsonAdapter, httpRequestRunner: httpRequestRunner, globalDataStore: globalDataStore, logger: logger, timer: simpleTimer, retryPolicy: httpRetryPolicy, userAgentUtil: userAgentUtil) } // GlobalDataStore @@ -183,8 +172,7 @@ extension DIGraph { } public var sharedHooksManager: HooksManager { - // Use a DispatchQueue to make singleton thread safe. You must create unique dispatchqueues instead of using 1 - // shared one or you will get a crash when trying + // Use a DispatchQueue to make singleton thread safe. You must create unique dispatchqueues instead of using 1 shared one or you will get a crash when trying // to call DispatchQueue.sync{} while already inside another DispatchQueue.sync{} call. DispatchQueue(label: "DIGraph_HooksManager_singleton_access").sync { if let overridenDep = self.overrides[String(describing: HooksManager.self)] { @@ -222,16 +210,7 @@ extension DIGraph { } private var newQueue: Queue { - CioQueue( - siteId: siteId, - storage: queueStorage, - runRequest: queueRunRequest, - jsonAdapter: jsonAdapter, - logger: logger, - sdkConfig: sdkConfig, - queueTimer: singleScheduleTimer, - dateUtil: dateUtil - ) + CioQueue(siteId: siteId, storage: queueStorage, runRequest: queueRunRequest, jsonAdapter: jsonAdapter, logger: logger, sdkConfig: sdkConfig, queueTimer: singleScheduleTimer, dateUtil: dateUtil) } // QueueQueryRunner @@ -255,15 +234,13 @@ extension DIGraph { } public var sharedQueueRequestManager: QueueRequestManager { - // Use a DispatchQueue to make singleton thread safe. You must create unique dispatchqueues instead of using 1 - // shared one or you will get a crash when trying + // Use a DispatchQueue to make singleton thread safe. You must create unique dispatchqueues instead of using 1 shared one or you will get a crash when trying // to call DispatchQueue.sync{} while already inside another DispatchQueue.sync{} call. DispatchQueue(label: "DIGraph_QueueRequestManager_singleton_access").sync { if let overridenDep = self.overrides[String(describing: QueueRequestManager.self)] { return overridenDep as! QueueRequestManager } - let existingSingletonInstance = self - .singletons[String(describing: QueueRequestManager.self)] as? QueueRequestManager + let existingSingletonInstance = self.singletons[String(describing: QueueRequestManager.self)] as? QueueRequestManager let instance = existingSingletonInstance ?? _get_queueRequestManager() self.singletons[String(describing: QueueRequestManager.self)] = instance return instance @@ -283,13 +260,7 @@ extension DIGraph { } private var newQueueRunRequest: QueueRunRequest { - CioQueueRunRequest( - runner: queueRunner, - storage: queueStorage, - requestManager: queueRequestManager, - logger: logger, - queryRunner: queueQueryRunner - ) + CioQueueRunRequest(runner: queueRunner, storage: queueStorage, requestManager: queueRequestManager, logger: logger, queryRunner: queueQueryRunner) } // QueueRunner @@ -301,14 +272,7 @@ extension DIGraph { } private var newQueueRunner: QueueRunner { - CioQueueRunner( - siteId: siteId, - jsonAdapter: jsonAdapter, - logger: logger, - httpClient: httpClient, - hooksManager: hooksManager, - sdkConfig: sdkConfig - ) + CioQueueRunner(siteId: siteId, jsonAdapter: jsonAdapter, logger: logger, httpClient: httpClient, hooksManager: hooksManager, sdkConfig: sdkConfig) } // SimpleTimer @@ -332,15 +296,13 @@ extension DIGraph { } internal var sharedSingleScheduleTimer: SingleScheduleTimer { - // Use a DispatchQueue to make singleton thread safe. You must create unique dispatchqueues instead of using 1 - // shared one or you will get a crash when trying + // Use a DispatchQueue to make singleton thread safe. You must create unique dispatchqueues instead of using 1 shared one or you will get a crash when trying // to call DispatchQueue.sync{} while already inside another DispatchQueue.sync{} call. DispatchQueue(label: "DIGraph_SingleScheduleTimer_singleton_access").sync { if let overridenDep = self.overrides[String(describing: SingleScheduleTimer.self)] { return overridenDep as! SingleScheduleTimer } - let existingSingletonInstance = self - .singletons[String(describing: SingleScheduleTimer.self)] as? SingleScheduleTimer + let existingSingletonInstance = self.singletons[String(describing: SingleScheduleTimer.self)] as? SingleScheduleTimer let instance = existingSingletonInstance ?? _get_singleScheduleTimer() self.singletons[String(describing: SingleScheduleTimer.self)] = instance return instance @@ -420,15 +382,7 @@ extension DIGraph { } private var newQueueStorage: QueueStorage { - FileManagerQueueStorage( - siteId: siteId, - fileStorage: fileStorage, - jsonAdapter: jsonAdapter, - lockManager: lockManager, - sdkConfig: sdkConfig, - logger: logger, - dateUtil: dateUtil - ) + FileManagerQueueStorage(siteId: siteId, fileStorage: fileStorage, jsonAdapter: jsonAdapter, lockManager: lockManager, sdkConfig: sdkConfig, logger: logger, dateUtil: dateUtil) } // JsonAdapter @@ -452,8 +406,7 @@ extension DIGraph { } public var sharedLockManager: LockManager { - // Use a DispatchQueue to make singleton thread safe. You must create unique dispatchqueues instead of using 1 - // shared one or you will get a crash when trying + // Use a DispatchQueue to make singleton thread safe. You must create unique dispatchqueues instead of using 1 shared one or you will get a crash when trying // to call DispatchQueue.sync{} while already inside another DispatchQueue.sync{} call. DispatchQueue(label: "DIGraph_LockManager_singleton_access").sync { if let overridenDep = self.overrides[String(describing: LockManager.self)] { diff --git a/Sources/Common/autogenerated/AutoLenses.generated.swift b/Sources/Common/autogenerated/AutoLenses.generated.swift index 19f4ed4e0..b2ebe9c25 100644 --- a/Sources/Common/autogenerated/AutoLenses.generated.swift +++ b/Sources/Common/autogenerated/AutoLenses.generated.swift @@ -109,113 +109,53 @@ extension QueueTaskMetadata { static let taskPersistedIdLens = Lens( get: { $0.taskPersistedId }, set: { taskPersistedId, existing in - QueueTaskMetadata( - taskPersistedId: taskPersistedId, - taskType: existing.taskType, - groupStart: existing.groupStart, - groupMember: existing.groupMember, - createdAt: existing.createdAt - ) + QueueTaskMetadata(taskPersistedId: taskPersistedId, taskType: existing.taskType, groupStart: existing.groupStart, groupMember: existing.groupMember, createdAt: existing.createdAt) } ) static let taskTypeLens = Lens( get: { $0.taskType }, set: { taskType, existing in - QueueTaskMetadata( - taskPersistedId: existing.taskPersistedId, - taskType: taskType, - groupStart: existing.groupStart, - groupMember: existing.groupMember, - createdAt: existing.createdAt - ) + QueueTaskMetadata(taskPersistedId: existing.taskPersistedId, taskType: taskType, groupStart: existing.groupStart, groupMember: existing.groupMember, createdAt: existing.createdAt) } ) static let groupStartLens = Lens( get: { $0.groupStart }, set: { groupStart, existing in - QueueTaskMetadata( - taskPersistedId: existing.taskPersistedId, - taskType: existing.taskType, - groupStart: groupStart, - groupMember: existing.groupMember, - createdAt: existing.createdAt - ) + QueueTaskMetadata(taskPersistedId: existing.taskPersistedId, taskType: existing.taskType, groupStart: groupStart, groupMember: existing.groupMember, createdAt: existing.createdAt) } ) static let groupMemberLens = Lens( get: { $0.groupMember }, set: { groupMember, existing in - QueueTaskMetadata( - taskPersistedId: existing.taskPersistedId, - taskType: existing.taskType, - groupStart: existing.groupStart, - groupMember: groupMember, - createdAt: existing.createdAt - ) + QueueTaskMetadata(taskPersistedId: existing.taskPersistedId, taskType: existing.taskType, groupStart: existing.groupStart, groupMember: groupMember, createdAt: existing.createdAt) } ) static let createdAtLens = Lens( get: { $0.createdAt }, set: { createdAt, existing in - QueueTaskMetadata( - taskPersistedId: existing.taskPersistedId, - taskType: existing.taskType, - groupStart: existing.groupStart, - groupMember: existing.groupMember, - createdAt: createdAt - ) + QueueTaskMetadata(taskPersistedId: existing.taskPersistedId, taskType: existing.taskType, groupStart: existing.groupStart, groupMember: existing.groupMember, createdAt: createdAt) } ) // Convenient set functions to edit a property of the immutable object func taskPersistedIdSet(_ taskPersistedId: String) -> QueueTaskMetadata { - QueueTaskMetadata( - taskPersistedId: taskPersistedId, - taskType: taskType, - groupStart: groupStart, - groupMember: groupMember, - createdAt: createdAt - ) + QueueTaskMetadata(taskPersistedId: taskPersistedId, taskType: taskType, groupStart: groupStart, groupMember: groupMember, createdAt: createdAt) } func taskTypeSet(_ taskType: String) -> QueueTaskMetadata { - QueueTaskMetadata( - taskPersistedId: taskPersistedId, - taskType: taskType, - groupStart: groupStart, - groupMember: groupMember, - createdAt: createdAt - ) + QueueTaskMetadata(taskPersistedId: taskPersistedId, taskType: taskType, groupStart: groupStart, groupMember: groupMember, createdAt: createdAt) } func groupStartSet(_ groupStart: String?) -> QueueTaskMetadata { - QueueTaskMetadata( - taskPersistedId: taskPersistedId, - taskType: taskType, - groupStart: groupStart, - groupMember: groupMember, - createdAt: createdAt - ) + QueueTaskMetadata(taskPersistedId: taskPersistedId, taskType: taskType, groupStart: groupStart, groupMember: groupMember, createdAt: createdAt) } func groupMemberSet(_ groupMember: [String]?) -> QueueTaskMetadata { - QueueTaskMetadata( - taskPersistedId: taskPersistedId, - taskType: taskType, - groupStart: groupStart, - groupMember: groupMember, - createdAt: createdAt - ) + QueueTaskMetadata(taskPersistedId: taskPersistedId, taskType: taskType, groupStart: groupStart, groupMember: groupMember, createdAt: createdAt) } func createdAtSet(_ createdAt: Date) -> QueueTaskMetadata { - QueueTaskMetadata( - taskPersistedId: taskPersistedId, - taskType: taskType, - groupStart: groupStart, - groupMember: groupMember, - createdAt: createdAt - ) + QueueTaskMetadata(taskPersistedId: taskPersistedId, taskType: taskType, groupStart: groupStart, groupMember: groupMember, createdAt: createdAt) } } diff --git a/Sources/Common/autogenerated/AutoMockable.generated.swift b/Sources/Common/autogenerated/AutoMockable.generated.swift index 2cd40474b..58f0eaef8 100644 --- a/Sources/Common/autogenerated/AutoMockable.generated.swift +++ b/Sources/Common/autogenerated/AutoMockable.generated.swift @@ -465,8 +465,7 @@ public class DeviceInfoMock: DeviceInfo, Mock { */ public var isPushSubscribedClosure: (((Bool) -> Void) -> Void)? - /// Mocked function for `isPushSubscribed(completion: @escaping (Bool) -> Void)`. Your opportunity to return a - /// mocked value and check result of mock in test code. + /// Mocked function for `isPushSubscribed(completion: @escaping (Bool) -> Void)`. Your opportunity to return a mocked value and check result of mock in test code. public func isPushSubscribed(completion: @escaping (Bool) -> Void) { mockCalled = true isPushSubscribedCallsCount += 1 @@ -589,8 +588,7 @@ public class FileStorageMock: FileStorage, Mock { */ public var saveClosure: ((FileType, Data, String?) -> Bool)? - /// Mocked function for `save(type: FileType, contents: Data, fileId: String?)`. Your opportunity to return a mocked - /// value and check result of mock in test code. + /// Mocked function for `save(type: FileType, contents: Data, fileId: String?)`. Your opportunity to return a mocked value and check result of mock in test code. public func save(type: FileType, contents: Data, fileId: String?) -> Bool { mockCalled = true saveCallsCount += 1 @@ -621,8 +619,7 @@ public class FileStorageMock: FileStorage, Mock { */ public var getClosure: ((FileType, String?) -> Data?)? - /// Mocked function for `get(type: FileType, fileId: String?)`. Your opportunity to return a mocked value and check - /// result of mock in test code. + /// Mocked function for `get(type: FileType, fileId: String?)`. Your opportunity to return a mocked value and check result of mock in test code. public func get(type: FileType, fileId: String?) -> Data? { mockCalled = true getCallsCount += 1 @@ -653,8 +650,7 @@ public class FileStorageMock: FileStorage, Mock { */ public var deleteClosure: ((FileType, String) -> Bool)? - /// Mocked function for `delete(type: FileType, fileId: String)`. Your opportunity to return a mocked value and - /// check result of mock in test code. + /// Mocked function for `delete(type: FileType, fileId: String)`. Your opportunity to return a mocked value and check result of mock in test code. public func delete(type: FileType, fileId: String) -> Bool { mockCalled = true deleteCallsCount += 1 @@ -777,8 +773,7 @@ public class GlobalDataStoreMock: GlobalDataStore, Mock { */ public var deleteAllClosure: (() -> Void)? - /// Mocked function for `deleteAll()`. Your opportunity to return a mocked value and check result of mock in test - /// code. + /// Mocked function for `deleteAll()`. Your opportunity to return a mocked value and check result of mock in test code. public func deleteAll() { mockCalled = true deleteAllCallsCount += 1 @@ -941,8 +936,7 @@ public class HooksManagerMock: HooksManager, Mock { */ public var addClosure: ((HookModule, ModuleHookProvider) -> Void)? - /// Mocked function for `add(key: HookModule, provider: ModuleHookProvider)`. Your opportunity to return a mocked - /// value and check result of mock in test code. + /// Mocked function for `add(key: HookModule, provider: ModuleHookProvider)`. Your opportunity to return a mocked value and check result of mock in test code. public func add(key: HookModule, provider: ModuleHookProvider) { mockCalled = true addCallsCount += 1 @@ -995,22 +989,15 @@ public class HttpClientMock: HttpClient, Mock { } /// The arguments from the *last* time the function was called. - public private(set) var requestReceivedArguments: ( - params: HttpRequestParams, - onComplete: (Result) -> Void - )? + public private(set) var requestReceivedArguments: (params: HttpRequestParams, onComplete: (Result) -> Void)? /// Arguments from *all* of the times that the function was called. - public private(set) var requestReceivedInvocations: [( - params: HttpRequestParams, - onComplete: (Result) -> Void - )] = [] + public private(set) var requestReceivedInvocations: [(params: HttpRequestParams, onComplete: (Result) -> Void)] = [] /** Set closure to get called when function gets called. Great way to test logic or return a value for the function. */ public var requestClosure: ((HttpRequestParams, (Result) -> Void) -> Void)? - /// Mocked function for `request(_ params: HttpRequestParams, onComplete: @escaping (Result) - /// -> Void)`. Your opportunity to return a mocked value and check result of mock in test code. + /// Mocked function for `request(_ params: HttpRequestParams, onComplete: @escaping (Result) -> Void)`. Your opportunity to return a mocked value and check result of mock in test code. public func request(_ params: HttpRequestParams, onComplete: @escaping (Result) -> Void) { mockCalled = true requestCallsCount += 1 @@ -1029,24 +1016,15 @@ public class HttpClientMock: HttpClient, Mock { } /// The arguments from the *last* time the function was called. - public private(set) var downloadFileReceivedArguments: ( - url: URL, - fileType: DownloadFileType, - onComplete: (URL?) -> Void - )? + public private(set) var downloadFileReceivedArguments: (url: URL, fileType: DownloadFileType, onComplete: (URL?) -> Void)? /// Arguments from *all* of the times that the function was called. - public private(set) var downloadFileReceivedInvocations: [( - url: URL, - fileType: DownloadFileType, - onComplete: (URL?) -> Void - )] = [] + public private(set) var downloadFileReceivedInvocations: [(url: URL, fileType: DownloadFileType, onComplete: (URL?) -> Void)] = [] /** Set closure to get called when function gets called. Great way to test logic or return a value for the function. */ public var downloadFileClosure: ((URL, DownloadFileType, (URL?) -> Void) -> Void)? - /// Mocked function for `downloadFile(url: URL, fileType: DownloadFileType, onComplete: @escaping (URL?) -> Void)`. - /// Your opportunity to return a mocked value and check result of mock in test code. + /// Mocked function for `downloadFile(url: URL, fileType: DownloadFileType, onComplete: @escaping (URL?) -> Void)`. Your opportunity to return a mocked value and check result of mock in test code. public func downloadFile(url: URL, fileType: DownloadFileType, onComplete: @escaping (URL?) -> Void) { mockCalled = true downloadFileCallsCount += 1 @@ -1073,8 +1051,7 @@ public class HttpClientMock: HttpClient, Mock { */ public var cancelClosure: ((Bool) -> Void)? - /// Mocked function for `cancel(finishTasks: Bool)`. Your opportunity to return a mocked value and check result of - /// mock in test code. + /// Mocked function for `cancel(finishTasks: Bool)`. Your opportunity to return a mocked value and check result of mock in test code. public func cancel(finishTasks: Bool) { mockCalled = true cancelCallsCount += 1 @@ -1122,30 +1099,16 @@ internal class HttpRequestRunnerMock: HttpRequestRunner, Mock { } /// The arguments from the *last* time the function was called. - internal private(set) var requestReceivedArguments: ( - params: HttpRequestParams, - session: URLSession, - onComplete: (Data?, HTTPURLResponse?, Error?) -> Void - )? + internal private(set) var requestReceivedArguments: (params: HttpRequestParams, session: URLSession, onComplete: (Data?, HTTPURLResponse?, Error?) -> Void)? /// Arguments from *all* of the times that the function was called. - internal private(set) var requestReceivedInvocations: [( - params: HttpRequestParams, - session: URLSession, - onComplete: (Data?, HTTPURLResponse?, Error?) -> Void - )] = [] + internal private(set) var requestReceivedInvocations: [(params: HttpRequestParams, session: URLSession, onComplete: (Data?, HTTPURLResponse?, Error?) -> Void)] = [] /** Set closure to get called when function gets called. Great way to test logic or return a value for the function. */ internal var requestClosure: ((HttpRequestParams, URLSession, (Data?, HTTPURLResponse?, Error?) -> Void) -> Void)? - /// Mocked function for `request(params: HttpRequestParams, session: URLSession, onComplete: @escaping (Data?, - /// HTTPURLResponse?, Error?) -> Void)`. Your opportunity to return a mocked value and check result of mock in test - /// code. - internal func request( - params: HttpRequestParams, - session: URLSession, - onComplete: @escaping (Data?, HTTPURLResponse?, Error?) -> Void - ) { + /// Mocked function for `request(params: HttpRequestParams, session: URLSession, onComplete: @escaping (Data?, HTTPURLResponse?, Error?) -> Void)`. Your opportunity to return a mocked value and check result of mock in test code. + internal func request(params: HttpRequestParams, session: URLSession, onComplete: @escaping (Data?, HTTPURLResponse?, Error?) -> Void) { mockCalled = true requestCallsCount += 1 requestReceivedArguments = (params: params, session: session, onComplete: onComplete) @@ -1163,32 +1126,16 @@ internal class HttpRequestRunnerMock: HttpRequestRunner, Mock { } /// The arguments from the *last* time the function was called. - internal private(set) var downloadFileReceivedArguments: ( - url: URL, - fileType: DownloadFileType, - session: URLSession, - onComplete: (URL?) -> Void - )? + internal private(set) var downloadFileReceivedArguments: (url: URL, fileType: DownloadFileType, session: URLSession, onComplete: (URL?) -> Void)? /// Arguments from *all* of the times that the function was called. - internal private(set) var downloadFileReceivedInvocations: [( - url: URL, - fileType: DownloadFileType, - session: URLSession, - onComplete: (URL?) -> Void - )] = [] + internal private(set) var downloadFileReceivedInvocations: [(url: URL, fileType: DownloadFileType, session: URLSession, onComplete: (URL?) -> Void)] = [] /** Set closure to get called when function gets called. Great way to test logic or return a value for the function. */ internal var downloadFileClosure: ((URL, DownloadFileType, URLSession, (URL?) -> Void) -> Void)? - /// Mocked function for `downloadFile(url: URL, fileType: DownloadFileType, session: URLSession, onComplete: - /// @escaping (URL?) -> Void)`. Your opportunity to return a mocked value and check result of mock in test code. - internal func downloadFile( - url: URL, - fileType: DownloadFileType, - session: URLSession, - onComplete: @escaping (URL?) -> Void - ) { + /// Mocked function for `downloadFile(url: URL, fileType: DownloadFileType, session: URLSession, onComplete: @escaping (URL?) -> Void)`. Your opportunity to return a mocked value and check result of mock in test code. + internal func downloadFile(url: URL, fileType: DownloadFileType, session: URLSession, onComplete: @escaping (URL?) -> Void) { mockCalled = true downloadFileCallsCount += 1 downloadFileReceivedArguments = (url: url, fileType: fileType, session: session, onComplete: onComplete) @@ -1306,8 +1253,7 @@ public class LoggerMock: Logger, Mock { */ public var debugClosure: ((String) -> Void)? - /// Mocked function for `debug(_ message: String)`. Your opportunity to return a mocked value and check result of - /// mock in test code. + /// Mocked function for `debug(_ message: String)`. Your opportunity to return a mocked value and check result of mock in test code. public func debug(_ message: String) { mockCalled = true debugCallsCount += 1 @@ -1334,8 +1280,7 @@ public class LoggerMock: Logger, Mock { */ public var infoClosure: ((String) -> Void)? - /// Mocked function for `info(_ message: String)`. Your opportunity to return a mocked value and check result of - /// mock in test code. + /// Mocked function for `info(_ message: String)`. Your opportunity to return a mocked value and check result of mock in test code. public func info(_ message: String) { mockCalled = true infoCallsCount += 1 @@ -1362,8 +1307,7 @@ public class LoggerMock: Logger, Mock { */ public var errorClosure: ((String) -> Void)? - /// Mocked function for `error(_ message: String)`. Your opportunity to return a mocked value and check result of - /// mock in test code. + /// Mocked function for `error(_ message: String)`. Your opportunity to return a mocked value and check result of mock in test code. public func error(_ message: String) { mockCalled = true errorCallsCount += 1 @@ -1552,28 +1496,20 @@ public class ProfileIdentifyHookMock: ProfileIdentifyHook, Mock { } /// The arguments from the *last* time the function was called. - public private(set) var beforeIdentifiedProfileChangeReceivedArguments: ( - oldIdentifier: String, - newIdentifier: String - )? + public private(set) var beforeIdentifiedProfileChangeReceivedArguments: (oldIdentifier: String, newIdentifier: String)? /// Arguments from *all* of the times that the function was called. - public private(set) var beforeIdentifiedProfileChangeReceivedInvocations: [( - oldIdentifier: String, - newIdentifier: String - )] = [] + public private(set) var beforeIdentifiedProfileChangeReceivedInvocations: [(oldIdentifier: String, newIdentifier: String)] = [] /** Set closure to get called when function gets called. Great way to test logic or return a value for the function. */ public var beforeIdentifiedProfileChangeClosure: ((String, String) -> Void)? - /// Mocked function for `beforeIdentifiedProfileChange(oldIdentifier: String, newIdentifier: String)`. Your - /// opportunity to return a mocked value and check result of mock in test code. + /// Mocked function for `beforeIdentifiedProfileChange(oldIdentifier: String, newIdentifier: String)`. Your opportunity to return a mocked value and check result of mock in test code. public func beforeIdentifiedProfileChange(oldIdentifier: String, newIdentifier: String) { mockCalled = true beforeIdentifiedProfileChangeCallsCount += 1 beforeIdentifiedProfileChangeReceivedArguments = (oldIdentifier: oldIdentifier, newIdentifier: newIdentifier) - beforeIdentifiedProfileChangeReceivedInvocations - .append((oldIdentifier: oldIdentifier, newIdentifier: newIdentifier)) + beforeIdentifiedProfileChangeReceivedInvocations.append((oldIdentifier: oldIdentifier, newIdentifier: newIdentifier)) beforeIdentifiedProfileChangeClosure?(oldIdentifier, newIdentifier) } @@ -1595,8 +1531,7 @@ public class ProfileIdentifyHookMock: ProfileIdentifyHook, Mock { */ public var profileIdentifiedClosure: ((String) -> Void)? - /// Mocked function for `profileIdentified(identifier: String)`. Your opportunity to return a mocked value and check - /// result of mock in test code. + /// Mocked function for `profileIdentified(identifier: String)`. Your opportunity to return a mocked value and check result of mock in test code. public func profileIdentified(identifier: String) { mockCalled = true profileIdentifiedCallsCount += 1 @@ -1623,8 +1558,7 @@ public class ProfileIdentifyHookMock: ProfileIdentifyHook, Mock { */ public var beforeProfileStoppedBeingIdentifiedClosure: ((String) -> Void)? - /// Mocked function for `beforeProfileStoppedBeingIdentified(oldIdentifier: String)`. Your opportunity to return a - /// mocked value and check result of mock in test code. + /// Mocked function for `beforeProfileStoppedBeingIdentified(oldIdentifier: String)`. Your opportunity to return a mocked value and check result of mock in test code. public func beforeProfileStoppedBeingIdentified(oldIdentifier: String) { mockCalled = true beforeProfileStoppedBeingIdentifiedCallsCount += 1 @@ -1740,8 +1674,7 @@ public class QueueMock: Queue, Mock { /// The arguments from the *last* time the function was called. public private(set) var addTrackInAppDeliveryTaskReceivedArguments: (deliveryId: String, event: InAppMetric)? /// Arguments from *all* of the times that the function was called. - public private(set) var addTrackInAppDeliveryTaskReceivedInvocations: [(deliveryId: String, event: InAppMetric)] = - [] + public private(set) var addTrackInAppDeliveryTaskReceivedInvocations: [(deliveryId: String, event: InAppMetric)] = [] /// Value to return from the mocked function. public var addTrackInAppDeliveryTaskReturnValue: ModifyQueueResult! /** @@ -1751,8 +1684,7 @@ public class QueueMock: Queue, Mock { */ public var addTrackInAppDeliveryTaskClosure: ((String, InAppMetric) -> ModifyQueueResult)? - /// Mocked function for `addTrackInAppDeliveryTask(deliveryId: String, event: InAppMetric)`. Your opportunity to - /// return a mocked value and check result of mock in test code. + /// Mocked function for `addTrackInAppDeliveryTask(deliveryId: String, event: InAppMetric)`. Your opportunity to return a mocked value and check result of mock in test code. public func addTrackInAppDeliveryTask(deliveryId: String, event: InAppMetric) -> ModifyQueueResult { mockCalled = true addTrackInAppDeliveryTaskCallsCount += 1 @@ -1771,19 +1703,9 @@ public class QueueMock: Queue, Mock { } /// The arguments from the *last* time the function was called. - public private(set) var addTaskReceivedArguments: ( - type: String, - data: AnyEncodable, - groupStart: QueueTaskGroup?, - blockingGroups: [QueueTaskGroup]? - )? + public private(set) var addTaskReceivedArguments: (type: String, data: AnyEncodable, groupStart: QueueTaskGroup?, blockingGroups: [QueueTaskGroup]?)? /// Arguments from *all* of the times that the function was called. - public private(set) var addTaskReceivedInvocations: [( - type: String, - data: AnyEncodable, - groupStart: QueueTaskGroup?, - blockingGroups: [QueueTaskGroup]? - )] = [] + public private(set) var addTaskReceivedInvocations: [(type: String, data: AnyEncodable, groupStart: QueueTaskGroup?, blockingGroups: [QueueTaskGroup]?)] = [] /// Value to return from the mocked function. public var addTaskReturnValue: ModifyQueueResult! /** @@ -1793,25 +1715,12 @@ public class QueueMock: Queue, Mock { */ public var addTaskClosure: ((String, AnyEncodable, QueueTaskGroup?, [QueueTaskGroup]?) -> ModifyQueueResult)? - /// Mocked function for `addTask(type: String, data: TaskData, groupStart: QueueTaskGroup?, - /// blockingGroups: [QueueTaskGroup]?)`. Your opportunity to return a mocked value and check result of mock in test - /// code. - public func addTask( - type: String, - data: TaskData, - groupStart: QueueTaskGroup?, - blockingGroups: [QueueTaskGroup]? - ) -> ModifyQueueResult { + /// Mocked function for `addTask(type: String, data: TaskData, groupStart: QueueTaskGroup?, blockingGroups: [QueueTaskGroup]?)`. Your opportunity to return a mocked value and check result of mock in test code. + public func addTask(type: String, data: TaskData, groupStart: QueueTaskGroup?, blockingGroups: [QueueTaskGroup]?) -> ModifyQueueResult { mockCalled = true addTaskCallsCount += 1 - addTaskReceivedArguments = ( - type: type, - data: AnyEncodable(data), - groupStart: groupStart, - blockingGroups: blockingGroups - ) - addTaskReceivedInvocations - .append((type: type, data: AnyEncodable(data), groupStart: groupStart, blockingGroups: blockingGroups)) + addTaskReceivedArguments = (type: type, data: AnyEncodable(data), groupStart: groupStart, blockingGroups: blockingGroups) + addTaskReceivedInvocations.append((type: type, data: AnyEncodable(data), groupStart: groupStart, blockingGroups: blockingGroups)) return addTaskClosure.map { $0(type, AnyEncodable(data), groupStart, blockingGroups) } ?? addTaskReturnValue } @@ -1833,8 +1742,7 @@ public class QueueMock: Queue, Mock { */ public var runClosure: ((() -> Void) -> Void)? - /// Mocked function for `run(onComplete: @escaping () -> Void)`. Your opportunity to return a mocked value and check - /// result of mock in test code. + /// Mocked function for `run(onComplete: @escaping () -> Void)`. Your opportunity to return a mocked value and check result of mock in test code. public func run(onComplete: @escaping () -> Void) { mockCalled = true runCallsCount += 1 @@ -1857,8 +1765,7 @@ public class QueueMock: Queue, Mock { */ public var deleteExpiredTasksClosure: (() -> Void)? - /// Mocked function for `deleteExpiredTasks()`. Your opportunity to return a mocked value and check result of mock - /// in test code. + /// Mocked function for `deleteExpiredTasks()`. Your opportunity to return a mocked value and check result of mock in test code. public func deleteExpiredTasks() { mockCalled = true deleteExpiredTasksCallsCount += 1 @@ -1902,17 +1809,9 @@ internal class QueueQueryRunnerMock: QueueQueryRunner, Mock { } /// The arguments from the *last* time the function was called. - internal private(set) var getNextTaskReceivedArguments: ( - queue: [QueueTaskMetadata], - lastRanTask: QueueTaskMetadata?, - lastFailedTask: QueueTaskMetadata? - )? + internal private(set) var getNextTaskReceivedArguments: (queue: [QueueTaskMetadata], lastRanTask: QueueTaskMetadata?, lastFailedTask: QueueTaskMetadata?)? /// Arguments from *all* of the times that the function was called. - internal private(set) var getNextTaskReceivedInvocations: [( - queue: [QueueTaskMetadata], - lastRanTask: QueueTaskMetadata?, - lastFailedTask: QueueTaskMetadata? - )] = [] + internal private(set) var getNextTaskReceivedInvocations: [(queue: [QueueTaskMetadata], lastRanTask: QueueTaskMetadata?, lastFailedTask: QueueTaskMetadata?)] = [] /// Value to return from the mocked function. internal var getNextTaskReturnValue: QueueTaskMetadata? /** @@ -1920,18 +1819,10 @@ internal class QueueQueryRunnerMock: QueueQueryRunner, Mock { The closure has first priority to return a value for the mocked function. If the closure returns `nil`, then the mock will attempt to return the value for `getNextTaskReturnValue` */ - internal var getNextTaskClosure: ( - ([QueueTaskMetadata], QueueTaskMetadata?, QueueTaskMetadata?) - -> QueueTaskMetadata? - )? - - /// Mocked function for `getNextTask(_ queue: [QueueTaskMetadata], lastRanTask: QueueTaskMetadata?, lastFailedTask: - /// QueueTaskMetadata?)`. Your opportunity to return a mocked value and check result of mock in test code. - internal func getNextTask( - _ queue: [QueueTaskMetadata], - lastRanTask: QueueTaskMetadata?, - lastFailedTask: QueueTaskMetadata? - ) -> QueueTaskMetadata? { + internal var getNextTaskClosure: (([QueueTaskMetadata], QueueTaskMetadata?, QueueTaskMetadata?) -> QueueTaskMetadata?)? + + /// Mocked function for `getNextTask(_ queue: [QueueTaskMetadata], lastRanTask: QueueTaskMetadata?, lastFailedTask: QueueTaskMetadata?)`. Your opportunity to return a mocked value and check result of mock in test code. + internal func getNextTask(_ queue: [QueueTaskMetadata], lastRanTask: QueueTaskMetadata?, lastFailedTask: QueueTaskMetadata?) -> QueueTaskMetadata? { mockCalled = true getNextTaskCallsCount += 1 getNextTaskReceivedArguments = (queue: queue, lastRanTask: lastRanTask, lastFailedTask: lastFailedTask) @@ -2001,8 +1892,7 @@ public class QueueRequestManagerMock: QueueRequestManager, Mock { */ public var requestCompleteClosure: (() -> Void)? - /// Mocked function for `requestComplete()`. Your opportunity to return a mocked value and check result of mock in - /// test code. + /// Mocked function for `requestComplete()`. Your opportunity to return a mocked value and check result of mock in test code. public func requestComplete() { mockCalled = true requestCompleteCallsCount += 1 @@ -2031,8 +1921,7 @@ public class QueueRequestManagerMock: QueueRequestManager, Mock { */ public var startRequestClosure: ((() -> Void) -> Bool)? - /// Mocked function for `startRequest(onComplete: @escaping () -> Void)`. Your opportunity to return a mocked value - /// and check result of mock in test code. + /// Mocked function for `startRequest(onComplete: @escaping () -> Void)`. Your opportunity to return a mocked value and check result of mock in test code. public func startRequest(onComplete: @escaping () -> Void) -> Bool { mockCalled = true startRequestCallsCount += 1 @@ -2083,8 +1972,7 @@ public class QueueRunRequestMock: QueueRunRequest, Mock { */ public var startClosure: ((() -> Void) -> Void)? - /// Mocked function for `start(onComplete: @escaping () -> Void)`. Your opportunity to return a mocked value and - /// check result of mock in test code. + /// Mocked function for `start(onComplete: @escaping () -> Void)`. Your opportunity to return a mocked value and check result of mock in test code. public func start(onComplete: @escaping () -> Void) { mockCalled = true startCallsCount += 1 @@ -2127,22 +2015,15 @@ public class QueueRunnerMock: QueueRunner, Mock { } /// The arguments from the *last* time the function was called. - public private(set) var runTaskReceivedArguments: ( - task: QueueTask, - onComplete: (Result) -> Void - )? + public private(set) var runTaskReceivedArguments: (task: QueueTask, onComplete: (Result) -> Void)? /// Arguments from *all* of the times that the function was called. - public private(set) var runTaskReceivedInvocations: [( - task: QueueTask, - onComplete: (Result) -> Void - )] = [] + public private(set) var runTaskReceivedInvocations: [(task: QueueTask, onComplete: (Result) -> Void)] = [] /** Set closure to get called when function gets called. Great way to test logic or return a value for the function. */ public var runTaskClosure: ((QueueTask, (Result) -> Void) -> Void)? - /// Mocked function for `runTask(_ task: QueueTask, onComplete: @escaping (Result) -> - /// Void)`. Your opportunity to return a mocked value and check result of mock in test code. + /// Mocked function for `runTask(_ task: QueueTask, onComplete: @escaping (Result) -> Void)`. Your opportunity to return a mocked value and check result of mock in test code. public func runTask(_ task: QueueTask, onComplete: @escaping (Result) -> Void) { mockCalled = true runTaskCallsCount += 1 @@ -2185,15 +2066,9 @@ public class QueueRunnerHookMock: QueueRunnerHook, Mock { } /// The arguments from the *last* time the function was called. - public private(set) var runTaskReceivedArguments: ( - task: QueueTask, - onComplete: (Result) -> Void - )? + public private(set) var runTaskReceivedArguments: (task: QueueTask, onComplete: (Result) -> Void)? /// Arguments from *all* of the times that the function was called. - public private(set) var runTaskReceivedInvocations: [( - task: QueueTask, - onComplete: (Result) -> Void - )] = [] + public private(set) var runTaskReceivedInvocations: [(task: QueueTask, onComplete: (Result) -> Void)] = [] /// Value to return from the mocked function. public var runTaskReturnValue: Bool! /** @@ -2203,8 +2078,7 @@ public class QueueRunnerHookMock: QueueRunnerHook, Mock { */ public var runTaskClosure: ((QueueTask, (Result) -> Void) -> Bool)? - /// Mocked function for `runTask(_ task: QueueTask, onComplete: @escaping (Result) -> - /// Void)`. Your opportunity to return a mocked value and check result of mock in test code. + /// Mocked function for `runTask(_ task: QueueTask, onComplete: @escaping (Result) -> Void)`. Your opportunity to return a mocked value and check result of mock in test code. public func runTask(_ task: QueueTask, onComplete: @escaping (Result) -> Void) -> Bool { mockCalled = true runTaskCallsCount += 1 @@ -2281,8 +2155,7 @@ public class QueueStorageMock: QueueStorage, Mock { */ public var getInventoryClosure: (() -> [QueueTaskMetadata])? - /// Mocked function for `getInventory()`. Your opportunity to return a mocked value and check result of mock in test - /// code. + /// Mocked function for `getInventory()`. Your opportunity to return a mocked value and check result of mock in test code. public func getInventory() -> [QueueTaskMetadata] { mockCalled = true getInventoryCallsCount += 1 @@ -2311,8 +2184,7 @@ public class QueueStorageMock: QueueStorage, Mock { */ public var saveInventoryClosure: (([QueueTaskMetadata]) -> Bool)? - /// Mocked function for `saveInventory(_ inventory: [QueueTaskMetadata])`. Your opportunity to return a mocked value - /// and check result of mock in test code. + /// Mocked function for `saveInventory(_ inventory: [QueueTaskMetadata])`. Your opportunity to return a mocked value and check result of mock in test code. public func saveInventory(_ inventory: [QueueTaskMetadata]) -> Bool { mockCalled = true saveInventoryCallsCount += 1 @@ -2331,19 +2203,9 @@ public class QueueStorageMock: QueueStorage, Mock { } /// The arguments from the *last* time the function was called. - public private(set) var createReceivedArguments: ( - type: String, - data: Data, - groupStart: QueueTaskGroup?, - blockingGroups: [QueueTaskGroup]? - )? + public private(set) var createReceivedArguments: (type: String, data: Data, groupStart: QueueTaskGroup?, blockingGroups: [QueueTaskGroup]?)? /// Arguments from *all* of the times that the function was called. - public private(set) var createReceivedInvocations: [( - type: String, - data: Data, - groupStart: QueueTaskGroup?, - blockingGroups: [QueueTaskGroup]? - )] = [] + public private(set) var createReceivedInvocations: [(type: String, data: Data, groupStart: QueueTaskGroup?, blockingGroups: [QueueTaskGroup]?)] = [] /// Value to return from the mocked function. public var createReturnValue: CreateQueueStorageTaskResult! /** @@ -2353,19 +2215,12 @@ public class QueueStorageMock: QueueStorage, Mock { */ public var createClosure: ((String, Data, QueueTaskGroup?, [QueueTaskGroup]?) -> CreateQueueStorageTaskResult)? - /// Mocked function for `create(type: String, data: Data, groupStart: QueueTaskGroup?, blockingGroups: - /// [QueueTaskGroup]?)`. Your opportunity to return a mocked value and check result of mock in test code. - public func create( - type: String, - data: Data, - groupStart: QueueTaskGroup?, - blockingGroups: [QueueTaskGroup]? - ) -> CreateQueueStorageTaskResult { + /// Mocked function for `create(type: String, data: Data, groupStart: QueueTaskGroup?, blockingGroups: [QueueTaskGroup]?)`. Your opportunity to return a mocked value and check result of mock in test code. + public func create(type: String, data: Data, groupStart: QueueTaskGroup?, blockingGroups: [QueueTaskGroup]?) -> CreateQueueStorageTaskResult { mockCalled = true createCallsCount += 1 createReceivedArguments = (type: type, data: data, groupStart: groupStart, blockingGroups: blockingGroups) - createReceivedInvocations - .append((type: type, data: data, groupStart: groupStart, blockingGroups: blockingGroups)) + createReceivedInvocations.append((type: type, data: data, groupStart: groupStart, blockingGroups: blockingGroups)) return createClosure.map { $0(type, data, groupStart, blockingGroups) } ?? createReturnValue } @@ -2391,8 +2246,7 @@ public class QueueStorageMock: QueueStorage, Mock { */ public var updateClosure: ((String, QueueTaskRunResults) -> Bool)? - /// Mocked function for `update(storageId: String, runResults: QueueTaskRunResults)`. Your opportunity to return a - /// mocked value and check result of mock in test code. + /// Mocked function for `update(storageId: String, runResults: QueueTaskRunResults)`. Your opportunity to return a mocked value and check result of mock in test code. public func update(storageId: String, runResults: QueueTaskRunResults) -> Bool { mockCalled = true updateCallsCount += 1 @@ -2423,8 +2277,7 @@ public class QueueStorageMock: QueueStorage, Mock { */ public var getClosure: ((String) -> QueueTask?)? - /// Mocked function for `get(storageId: String)`. Your opportunity to return a mocked value and check result of mock - /// in test code. + /// Mocked function for `get(storageId: String)`. Your opportunity to return a mocked value and check result of mock in test code. public func get(storageId: String) -> QueueTask? { mockCalled = true getCallsCount += 1 @@ -2455,8 +2308,7 @@ public class QueueStorageMock: QueueStorage, Mock { */ public var deleteClosure: ((String) -> Bool)? - /// Mocked function for `delete(storageId: String)`. Your opportunity to return a mocked value and check result of - /// mock in test code. + /// Mocked function for `delete(storageId: String)`. Your opportunity to return a mocked value and check result of mock in test code. public func delete(storageId: String) -> Bool { mockCalled = true deleteCallsCount += 1 @@ -2483,8 +2335,7 @@ public class QueueStorageMock: QueueStorage, Mock { */ public var deleteExpiredClosure: (() -> [QueueTaskMetadata])? - /// Mocked function for `deleteExpired()`. Your opportunity to return a mocked value and check result of mock in - /// test code. + /// Mocked function for `deleteExpired()`. Your opportunity to return a mocked value and check result of mock in test code. public func deleteExpired() -> [QueueTaskMetadata] { mockCalled = true deleteExpiredCallsCount += 1 @@ -2533,8 +2384,7 @@ public class ScreenTrackingHookMock: ScreenTrackingHook, Mock { */ public var screenViewedClosure: ((String) -> Void)? - /// Mocked function for `screenViewed(name: String)`. Your opportunity to return a mocked value and check result of - /// mock in test code. + /// Mocked function for `screenViewed(name: String)`. Your opportunity to return a mocked value and check result of mock in test code. public func screenViewed(name: String) { mockCalled = true screenViewedCallsCount += 1 @@ -2593,8 +2443,7 @@ internal class SimpleTimerMock: SimpleTimer, Mock { */ internal var scheduleAndCancelPreviousClosure: ((Seconds, () -> Void) -> Void)? - /// Mocked function for `scheduleAndCancelPrevious(seconds: Seconds, block: @escaping () -> Void)`. Your opportunity - /// to return a mocked value and check result of mock in test code. + /// Mocked function for `scheduleAndCancelPrevious(seconds: Seconds, block: @escaping () -> Void)`. Your opportunity to return a mocked value and check result of mock in test code. internal func scheduleAndCancelPrevious(seconds: Seconds, block: @escaping () -> Void) { mockCalled = true scheduleAndCancelPreviousCallsCount += 1 @@ -2625,8 +2474,7 @@ internal class SimpleTimerMock: SimpleTimer, Mock { */ internal var scheduleIfNotAlreadyClosure: ((Seconds, () -> Void) -> Bool)? - /// Mocked function for `scheduleIfNotAlready(seconds: Seconds, block: @escaping () -> Void)`. Your opportunity to - /// return a mocked value and check result of mock in test code. + /// Mocked function for `scheduleIfNotAlready(seconds: Seconds, block: @escaping () -> Void)`. Your opportunity to return a mocked value and check result of mock in test code. internal func scheduleIfNotAlready(seconds: Seconds, block: @escaping () -> Void) -> Bool { mockCalled = true scheduleIfNotAlreadyCallsCount += 1 @@ -2705,8 +2553,7 @@ internal class SingleScheduleTimerMock: SingleScheduleTimer, Mock { */ internal var scheduleIfNotAlreadyClosure: ((Seconds, () -> Void) -> Bool)? - /// Mocked function for `scheduleIfNotAlready(seconds: Seconds, block: @escaping () -> Void)`. Your opportunity to - /// return a mocked value and check result of mock in test code. + /// Mocked function for `scheduleIfNotAlready(seconds: Seconds, block: @escaping () -> Void)`. Your opportunity to return a mocked value and check result of mock in test code. internal func scheduleIfNotAlready(seconds: Seconds, block: @escaping () -> Void) -> Bool { mockCalled = true scheduleIfNotAlreadyCallsCount += 1 @@ -2776,8 +2623,7 @@ public class UserAgentUtilMock: UserAgentUtil, Mock { */ public var getUserAgentHeaderValueClosure: (() -> String)? - /// Mocked function for `getUserAgentHeaderValue()`. Your opportunity to return a mocked value and check result of - /// mock in test code. + /// Mocked function for `getUserAgentHeaderValue()`. Your opportunity to return a mocked value and check result of mock in test code. public func getUserAgentHeaderValue() -> String { mockCalled = true getUserAgentHeaderValueCallsCount += 1 diff --git a/Sources/MessagingInApp/MessagingInAppImplementation.swift b/Sources/MessagingInApp/MessagingInAppImplementation.swift index df96dc3e0..fd6ca19ba 100644 --- a/Sources/MessagingInApp/MessagingInAppImplementation.swift +++ b/Sources/MessagingInApp/MessagingInAppImplementation.swift @@ -93,7 +93,6 @@ extension MessagingInAppImplementation: GistDelegate { eventListener?.messageActionTaken( message: InAppMessage(gistMessage: message), - currentRoute: currentRoute, action: action, name: name ) diff --git a/Sources/MessagingInApp/Type/InAppEventListener.swift b/Sources/MessagingInApp/Type/InAppEventListener.swift index c66cdb000..f49d69412 100644 --- a/Sources/MessagingInApp/Type/InAppEventListener.swift +++ b/Sources/MessagingInApp/Type/InAppEventListener.swift @@ -6,5 +6,5 @@ public protocol InAppEventListener: AutoMockable { func messageShown(message: InAppMessage) func messageDismissed(message: InAppMessage) func errorWithMessage(message: InAppMessage) - func messageActionTaken(message: InAppMessage, currentRoute: String, action: String, name: String) + func messageActionTaken(message: InAppMessage, action: String, name: String) } diff --git a/Sources/MessagingInApp/Type/InAppMessage.swift b/Sources/MessagingInApp/Type/InAppMessage.swift index 8a08d011b..75ba9979f 100644 --- a/Sources/MessagingInApp/Type/InAppMessage.swift +++ b/Sources/MessagingInApp/Type/InAppMessage.swift @@ -4,13 +4,11 @@ import Gist typealias GistMessage = Message public struct InAppMessage: Equatable { - public let instanceId: String public let messageId: String public let deliveryId: String? // (Currently taken from Gist's campaignId property). Can be nil when sending test // in-app messages internal init(gistMessage: GistMessage) { - self.instanceId = gistMessage.instanceId self.messageId = gistMessage.messageId self.deliveryId = gistMessage.gistProperties.campaignId } diff --git a/Sources/MessagingInApp/autogenerated/AutoMockable.generated.swift b/Sources/MessagingInApp/autogenerated/AutoMockable.generated.swift index 79d74afa7..dc1cf74b0 100644 --- a/Sources/MessagingInApp/autogenerated/AutoMockable.generated.swift +++ b/Sources/MessagingInApp/autogenerated/AutoMockable.generated.swift @@ -138,8 +138,7 @@ public class InAppEventListenerMock: InAppEventListener, Mock { */ public var messageShownClosure: ((InAppMessage) -> Void)? - /// Mocked function for `messageShown(message: InAppMessage)`. Your opportunity to return a mocked value and check - /// result of mock in test code. + /// Mocked function for `messageShown(message: InAppMessage)`. Your opportunity to return a mocked value and check result of mock in test code. public func messageShown(message: InAppMessage) { mockCalled = true messageShownCallsCount += 1 @@ -166,8 +165,7 @@ public class InAppEventListenerMock: InAppEventListener, Mock { */ public var messageDismissedClosure: ((InAppMessage) -> Void)? - /// Mocked function for `messageDismissed(message: InAppMessage)`. Your opportunity to return a mocked value and - /// check result of mock in test code. + /// Mocked function for `messageDismissed(message: InAppMessage)`. Your opportunity to return a mocked value and check result of mock in test code. public func messageDismissed(message: InAppMessage) { mockCalled = true messageDismissedCallsCount += 1 @@ -194,8 +192,7 @@ public class InAppEventListenerMock: InAppEventListener, Mock { */ public var errorWithMessageClosure: ((InAppMessage) -> Void)? - /// Mocked function for `errorWithMessage(message: InAppMessage)`. Your opportunity to return a mocked value and - /// check result of mock in test code. + /// Mocked function for `errorWithMessage(message: InAppMessage)`. Your opportunity to return a mocked value and check result of mock in test code. public func errorWithMessage(message: InAppMessage) { mockCalled = true errorWithMessageCallsCount += 1 @@ -214,33 +211,21 @@ public class InAppEventListenerMock: InAppEventListener, Mock { } /// The arguments from the *last* time the function was called. - public private(set) var messageActionTakenReceivedArguments: ( - message: InAppMessage, - currentRoute: String, - action: String, - name: String - )? + public private(set) var messageActionTakenReceivedArguments: (message: InAppMessage, action: String, name: String)? /// Arguments from *all* of the times that the function was called. - public private(set) var messageActionTakenReceivedInvocations: [( - message: InAppMessage, - currentRoute: String, - action: String, - name: String - )] = [] + public private(set) var messageActionTakenReceivedInvocations: [(message: InAppMessage, action: String, name: String)] = [] /** Set closure to get called when function gets called. Great way to test logic or return a value for the function. */ - public var messageActionTakenClosure: ((InAppMessage, String, String, String) -> Void)? + public var messageActionTakenClosure: ((InAppMessage, String, String) -> Void)? - /// Mocked function for `messageActionTaken(message: InAppMessage, currentRoute: String, action: String, name: - /// String)`. Your opportunity to return a mocked value and check result of mock in test code. - public func messageActionTaken(message: InAppMessage, currentRoute: String, action: String, name: String) { + /// Mocked function for `messageActionTaken(message: InAppMessage, action: String, name: String)`. Your opportunity to return a mocked value and check result of mock in test code. + public func messageActionTaken(message: InAppMessage, action: String, name: String) { mockCalled = true messageActionTakenCallsCount += 1 - messageActionTakenReceivedArguments = (message: message, currentRoute: currentRoute, action: action, name: name) - messageActionTakenReceivedInvocations - .append((message: message, currentRoute: currentRoute, action: action, name: name)) - messageActionTakenClosure?(message, currentRoute, action, name) + messageActionTakenReceivedArguments = (message: message, action: action, name: name) + messageActionTakenReceivedInvocations.append((message: message, action: action, name: name)) + messageActionTakenClosure?(message, action, name) } } @@ -298,8 +283,7 @@ internal class InAppProviderMock: InAppProvider, Mock { */ internal var initializeClosure: ((String, GistDelegate) -> Void)? - /// Mocked function for `initialize(organizationId: String, delegate: GistDelegate)`. Your opportunity to return a - /// mocked value and check result of mock in test code. + /// Mocked function for `initialize(organizationId: String, delegate: GistDelegate)`. Your opportunity to return a mocked value and check result of mock in test code. internal func initialize(organizationId: String, delegate: GistDelegate) { mockCalled = true initializeCallsCount += 1 @@ -326,8 +310,7 @@ internal class InAppProviderMock: InAppProvider, Mock { */ internal var setProfileIdentifierClosure: ((String) -> Void)? - /// Mocked function for `setProfileIdentifier(_ id: String)`. Your opportunity to return a mocked value and check - /// result of mock in test code. + /// Mocked function for `setProfileIdentifier(_ id: String)`. Your opportunity to return a mocked value and check result of mock in test code. internal func setProfileIdentifier(_ id: String) { mockCalled = true setProfileIdentifierCallsCount += 1 @@ -350,8 +333,7 @@ internal class InAppProviderMock: InAppProvider, Mock { */ internal var clearIdentifyClosure: (() -> Void)? - /// Mocked function for `clearIdentify()`. Your opportunity to return a mocked value and check result of mock in - /// test code. + /// Mocked function for `clearIdentify()`. Your opportunity to return a mocked value and check result of mock in test code. internal func clearIdentify() { mockCalled = true clearIdentifyCallsCount += 1 @@ -376,8 +358,7 @@ internal class InAppProviderMock: InAppProvider, Mock { */ internal var setRouteClosure: ((String) -> Void)? - /// Mocked function for `setRoute(_ route: String)`. Your opportunity to return a mocked value and check result of - /// mock in test code. + /// Mocked function for `setRoute(_ route: String)`. Your opportunity to return a mocked value and check result of mock in test code. internal func setRoute(_ route: String) { mockCalled = true setRouteCallsCount += 1 @@ -433,8 +414,7 @@ public class MessagingInAppInstanceMock: MessagingInAppInstance, Mock { */ public var initializeClosure: ((String) -> Void)? - /// Mocked function for `initialize(organizationId: String)`. Your opportunity to return a mocked value and check - /// result of mock in test code. + /// Mocked function for `initialize(organizationId: String)`. Your opportunity to return a mocked value and check result of mock in test code. public func initialize(organizationId: String) { mockCalled = true initializeCallsCount += 1 @@ -453,28 +433,20 @@ public class MessagingInAppInstanceMock: MessagingInAppInstance, Mock { } /// The arguments from the *last* time the function was called. - public private(set) var initializeEventListenerReceivedArguments: ( - organizationId: String, - eventListener: InAppEventListener - )? + public private(set) var initializeEventListenerReceivedArguments: (organizationId: String, eventListener: InAppEventListener)? /// Arguments from *all* of the times that the function was called. - public private(set) var initializeEventListenerReceivedInvocations: [( - organizationId: String, - eventListener: InAppEventListener - )] = [] + public private(set) var initializeEventListenerReceivedInvocations: [(organizationId: String, eventListener: InAppEventListener)] = [] /** Set closure to get called when function gets called. Great way to test logic or return a value for the function. */ public var initializeEventListenerClosure: ((String, InAppEventListener) -> Void)? - /// Mocked function for `initialize(organizationId: String, eventListener: InAppEventListener)`. Your opportunity to - /// return a mocked value and check result of mock in test code. + /// Mocked function for `initialize(organizationId: String, eventListener: InAppEventListener)`. Your opportunity to return a mocked value and check result of mock in test code. public func initialize(organizationId: String, eventListener: InAppEventListener) { mockCalled = true initializeEventListenerCallsCount += 1 initializeEventListenerReceivedArguments = (organizationId: organizationId, eventListener: eventListener) - initializeEventListenerReceivedInvocations - .append((organizationId: organizationId, eventListener: eventListener)) + initializeEventListenerReceivedInvocations.append((organizationId: organizationId, eventListener: eventListener)) initializeEventListenerClosure?(organizationId, eventListener) } } diff --git a/Sources/MessagingPush/autogenerated/AutoMockable.generated.swift b/Sources/MessagingPush/autogenerated/AutoMockable.generated.swift index f8a515019..0632721eb 100644 --- a/Sources/MessagingPush/autogenerated/AutoMockable.generated.swift +++ b/Sources/MessagingPush/autogenerated/AutoMockable.generated.swift @@ -156,8 +156,7 @@ public class MessagingPushInstanceMock: MessagingPushInstance, Mock { */ public var registerDeviceTokenClosure: ((String) -> Void)? - /// Mocked function for `registerDeviceToken(_ deviceToken: String)`. Your opportunity to return a mocked value and - /// check result of mock in test code. + /// Mocked function for `registerDeviceToken(_ deviceToken: String)`. Your opportunity to return a mocked value and check result of mock in test code. public func registerDeviceToken(_ deviceToken: String) { mockCalled = true registerDeviceTokenCallsCount += 1 @@ -180,8 +179,7 @@ public class MessagingPushInstanceMock: MessagingPushInstance, Mock { */ public var deleteDeviceTokenClosure: (() -> Void)? - /// Mocked function for `deleteDeviceToken()`. Your opportunity to return a mocked value and check result of mock in - /// test code. + /// Mocked function for `deleteDeviceToken()`. Your opportunity to return a mocked value and check result of mock in test code. public func deleteDeviceToken() { mockCalled = true deleteDeviceTokenCallsCount += 1 @@ -200,15 +198,13 @@ public class MessagingPushInstanceMock: MessagingPushInstance, Mock { /// The arguments from the *last* time the function was called. public private(set) var trackMetricReceivedArguments: (deliveryID: String, event: Metric, deviceToken: String)? /// Arguments from *all* of the times that the function was called. - public private(set) var trackMetricReceivedInvocations: [(deliveryID: String, event: Metric, deviceToken: String)] = - [] + public private(set) var trackMetricReceivedInvocations: [(deliveryID: String, event: Metric, deviceToken: String)] = [] /** Set closure to get called when function gets called. Great way to test logic or return a value for the function. */ public var trackMetricClosure: ((String, Metric, String) -> Void)? - /// Mocked function for `trackMetric(deliveryID: String, event: Metric, deviceToken: String)`. Your opportunity to - /// return a mocked value and check result of mock in test code. + /// Mocked function for `trackMetric(deliveryID: String, event: Metric, deviceToken: String)`. Your opportunity to return a mocked value and check result of mock in test code. public func trackMetric(deliveryID: String, event: Metric, deviceToken: String) { mockCalled = true trackMetricCallsCount += 1 @@ -228,15 +224,9 @@ public class MessagingPushInstanceMock: MessagingPushInstance, Mock { } /// The arguments from the *last* time the function was called. - public private(set) var didReceiveNotificationRequestReceivedArguments: ( - request: UNNotificationRequest, - contentHandler: (UNNotificationContent) -> Void - )? + public private(set) var didReceiveNotificationRequestReceivedArguments: (request: UNNotificationRequest, contentHandler: (UNNotificationContent) -> Void)? /// Arguments from *all* of the times that the function was called. - public private(set) var didReceiveNotificationRequestReceivedInvocations: [( - request: UNNotificationRequest, - contentHandler: (UNNotificationContent) -> Void - )] = [] + public private(set) var didReceiveNotificationRequestReceivedInvocations: [(request: UNNotificationRequest, contentHandler: (UNNotificationContent) -> Void)] = [] /// Value to return from the mocked function. public var didReceiveNotificationRequestReturnValue: Bool! /** @@ -246,20 +236,14 @@ public class MessagingPushInstanceMock: MessagingPushInstance, Mock { */ public var didReceiveNotificationRequestClosure: ((UNNotificationRequest, (UNNotificationContent) -> Void) -> Bool)? - /// Mocked function for `didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping - /// (UNNotificationContent) -> Void)`. Your opportunity to return a mocked value and check result of mock in test - /// code. + /// Mocked function for `didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void)`. Your opportunity to return a mocked value and check result of mock in test code. @discardableResult - public func didReceive( - _ request: UNNotificationRequest, - withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void - ) -> Bool { + public func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) -> Bool { mockCalled = true didReceiveNotificationRequestCallsCount += 1 didReceiveNotificationRequestReceivedArguments = (request: request, contentHandler: contentHandler) didReceiveNotificationRequestReceivedInvocations.append((request: request, contentHandler: contentHandler)) - return didReceiveNotificationRequestClosure - .map { $0(request, contentHandler) } ?? didReceiveNotificationRequestReturnValue + return didReceiveNotificationRequestClosure.map { $0(request, contentHandler) } ?? didReceiveNotificationRequestReturnValue } #endif @@ -278,8 +262,7 @@ public class MessagingPushInstanceMock: MessagingPushInstance, Mock { */ public var serviceExtensionTimeWillExpireClosure: (() -> Void)? - /// Mocked function for `serviceExtensionTimeWillExpire()`. Your opportunity to return a mocked value and check - /// result of mock in test code. + /// Mocked function for `serviceExtensionTimeWillExpire()`. Your opportunity to return a mocked value and check result of mock in test code. public func serviceExtensionTimeWillExpire() { mockCalled = true serviceExtensionTimeWillExpireCallsCount += 1 @@ -298,17 +281,9 @@ public class MessagingPushInstanceMock: MessagingPushInstance, Mock { } /// The arguments from the *last* time the function was called. - public private(set) var userNotificationCenter_withCompletionReceivedArguments: ( - center: UNUserNotificationCenter, - response: UNNotificationResponse, - completionHandler: () -> Void - )? + public private(set) var userNotificationCenter_withCompletionReceivedArguments: (center: UNUserNotificationCenter, response: UNNotificationResponse, completionHandler: () -> Void)? /// Arguments from *all* of the times that the function was called. - public private(set) var userNotificationCenter_withCompletionReceivedInvocations: [( - center: UNUserNotificationCenter, - response: UNNotificationResponse, - completionHandler: () -> Void - )] = [] + public private(set) var userNotificationCenter_withCompletionReceivedInvocations: [(center: UNUserNotificationCenter, response: UNNotificationResponse, completionHandler: () -> Void)] = [] /// Value to return from the mocked function. public var userNotificationCenter_withCompletionReturnValue: Bool! /** @@ -316,31 +291,15 @@ public class MessagingPushInstanceMock: MessagingPushInstance, Mock { The closure has first priority to return a value for the mocked function. If the closure returns `nil`, then the mock will attempt to return the value for `userNotificationCenter_withCompletionReturnValue` */ - public var userNotificationCenter_withCompletionClosure: (( - UNUserNotificationCenter, - UNNotificationResponse, - () -> Void - ) -> Bool)? - - /// Mocked function for `userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: - /// UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)`. Your opportunity to - /// return a mocked value and check result of mock in test code. - public func userNotificationCenter( - _ center: UNUserNotificationCenter, - didReceive response: UNNotificationResponse, - withCompletionHandler completionHandler: @escaping () -> Void - ) -> Bool { + public var userNotificationCenter_withCompletionClosure: ((UNUserNotificationCenter, UNNotificationResponse, () -> Void) -> Bool)? + + /// Mocked function for `userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)`. Your opportunity to return a mocked value and check result of mock in test code. + public func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) -> Bool { mockCalled = true userNotificationCenter_withCompletionCallsCount += 1 - userNotificationCenter_withCompletionReceivedArguments = ( - center: center, - response: response, - completionHandler: completionHandler - ) - userNotificationCenter_withCompletionReceivedInvocations - .append((center: center, response: response, completionHandler: completionHandler)) - return userNotificationCenter_withCompletionClosure - .map { $0(center, response, completionHandler) } ?? userNotificationCenter_withCompletionReturnValue + userNotificationCenter_withCompletionReceivedArguments = (center: center, response: response, completionHandler: completionHandler) + userNotificationCenter_withCompletionReceivedInvocations.append((center: center, response: response, completionHandler: completionHandler)) + return userNotificationCenter_withCompletionClosure.map { $0(center, response, completionHandler) } ?? userNotificationCenter_withCompletionReturnValue } #endif @@ -355,15 +314,9 @@ public class MessagingPushInstanceMock: MessagingPushInstance, Mock { } /// The arguments from the *last* time the function was called. - public private(set) var userNotificationCenterReceivedArguments: ( - center: UNUserNotificationCenter, - response: UNNotificationResponse - )? + public private(set) var userNotificationCenterReceivedArguments: (center: UNUserNotificationCenter, response: UNNotificationResponse)? /// Arguments from *all* of the times that the function was called. - public private(set) var userNotificationCenterReceivedInvocations: [( - center: UNUserNotificationCenter, - response: UNNotificationResponse - )] = [] + public private(set) var userNotificationCenterReceivedInvocations: [(center: UNUserNotificationCenter, response: UNNotificationResponse)] = [] /// Value to return from the mocked function. public var userNotificationCenterReturnValue: CustomerIOParsedPushPayload? /** @@ -371,17 +324,10 @@ public class MessagingPushInstanceMock: MessagingPushInstance, Mock { The closure has first priority to return a value for the mocked function. If the closure returns `nil`, then the mock will attempt to return the value for `userNotificationCenterReturnValue` */ - public var userNotificationCenterClosure: ( - (UNUserNotificationCenter, UNNotificationResponse) - -> CustomerIOParsedPushPayload? - )? - - /// Mocked function for `userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: - /// UNNotificationResponse)`. Your opportunity to return a mocked value and check result of mock in test code. - public func userNotificationCenter( - _ center: UNUserNotificationCenter, - didReceive response: UNNotificationResponse - ) -> CustomerIOParsedPushPayload? { + public var userNotificationCenterClosure: ((UNUserNotificationCenter, UNNotificationResponse) -> CustomerIOParsedPushPayload?)? + + /// Mocked function for `userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse)`. Your opportunity to return a mocked value and check result of mock in test code. + public func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse) -> CustomerIOParsedPushPayload? { mockCalled = true userNotificationCenterCallsCount += 1 userNotificationCenterReceivedArguments = (center: center, response: response) diff --git a/Sources/MessagingPushAPN/autogenerated/AutoMockable.generated.swift b/Sources/MessagingPushAPN/autogenerated/AutoMockable.generated.swift index f0cfc3110..858c21f29 100644 --- a/Sources/MessagingPushAPN/autogenerated/AutoMockable.generated.swift +++ b/Sources/MessagingPushAPN/autogenerated/AutoMockable.generated.swift @@ -153,8 +153,7 @@ public class MessagingPushAPNInstanceMock: MessagingPushAPNInstance, Mock { */ public var registerDeviceTokenClosure: ((Data) -> Void)? - /// Mocked function for `registerDeviceToken(apnDeviceToken: Data)`. Your opportunity to return a mocked value and - /// check result of mock in test code. + /// Mocked function for `registerDeviceToken(apnDeviceToken: Data)`. Your opportunity to return a mocked value and check result of mock in test code. public func registerDeviceToken(apnDeviceToken: Data) { mockCalled = true registerDeviceTokenCallsCount += 1 @@ -175,23 +174,18 @@ public class MessagingPushAPNInstanceMock: MessagingPushAPNInstance, Mock { /// The arguments from the *last* time the function was called. public private(set) var didRegisterForRemoteNotificationsReceivedArguments: (application: Any, deviceToken: Data)? /// Arguments from *all* of the times that the function was called. - public private(set) var didRegisterForRemoteNotificationsReceivedInvocations: [( - application: Any, - deviceToken: Data - )] = [] + public private(set) var didRegisterForRemoteNotificationsReceivedInvocations: [(application: Any, deviceToken: Data)] = [] /** Set closure to get called when function gets called. Great way to test logic or return a value for the function. */ public var didRegisterForRemoteNotificationsClosure: ((Any, Data) -> Void)? - /// Mocked function for `application(_ application: Any, didRegisterForRemoteNotificationsWithDeviceToken - /// deviceToken: Data)`. Your opportunity to return a mocked value and check result of mock in test code. + /// Mocked function for `application(_ application: Any, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)`. Your opportunity to return a mocked value and check result of mock in test code. public func application(_ application: Any, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { mockCalled = true didRegisterForRemoteNotificationsCallsCount += 1 didRegisterForRemoteNotificationsReceivedArguments = (application: application, deviceToken: deviceToken) - didRegisterForRemoteNotificationsReceivedInvocations - .append((application: application, deviceToken: deviceToken)) + didRegisterForRemoteNotificationsReceivedInvocations.append((application: application, deviceToken: deviceToken)) didRegisterForRemoteNotificationsClosure?(application, deviceToken) } @@ -207,17 +201,13 @@ public class MessagingPushAPNInstanceMock: MessagingPushAPNInstance, Mock { /// The arguments from the *last* time the function was called. public private(set) var didFailToRegisterForRemoteNotificationsReceivedArguments: (application: Any, error: Error)? /// Arguments from *all* of the times that the function was called. - public private(set) var didFailToRegisterForRemoteNotificationsReceivedInvocations: [( - application: Any, - error: Error - )] = [] + public private(set) var didFailToRegisterForRemoteNotificationsReceivedInvocations: [(application: Any, error: Error)] = [] /** Set closure to get called when function gets called. Great way to test logic or return a value for the function. */ public var didFailToRegisterForRemoteNotificationsClosure: ((Any, Error) -> Void)? - /// Mocked function for `application(_ application: Any, didFailToRegisterForRemoteNotificationsWithError error: - /// Error)`. Your opportunity to return a mocked value and check result of mock in test code. + /// Mocked function for `application(_ application: Any, didFailToRegisterForRemoteNotificationsWithError error: Error)`. Your opportunity to return a mocked value and check result of mock in test code. public func application(_ application: Any, didFailToRegisterForRemoteNotificationsWithError error: Error) { mockCalled = true didFailToRegisterForRemoteNotificationsCallsCount += 1 @@ -240,8 +230,7 @@ public class MessagingPushAPNInstanceMock: MessagingPushAPNInstance, Mock { */ public var deleteDeviceTokenClosure: (() -> Void)? - /// Mocked function for `deleteDeviceToken()`. Your opportunity to return a mocked value and check result of mock in - /// test code. + /// Mocked function for `deleteDeviceToken()`. Your opportunity to return a mocked value and check result of mock in test code. public func deleteDeviceToken() { mockCalled = true deleteDeviceTokenCallsCount += 1 @@ -260,15 +249,13 @@ public class MessagingPushAPNInstanceMock: MessagingPushAPNInstance, Mock { /// The arguments from the *last* time the function was called. public private(set) var trackMetricReceivedArguments: (deliveryID: String, event: Metric, deviceToken: String)? /// Arguments from *all* of the times that the function was called. - public private(set) var trackMetricReceivedInvocations: [(deliveryID: String, event: Metric, deviceToken: String)] = - [] + public private(set) var trackMetricReceivedInvocations: [(deliveryID: String, event: Metric, deviceToken: String)] = [] /** Set closure to get called when function gets called. Great way to test logic or return a value for the function. */ public var trackMetricClosure: ((String, Metric, String) -> Void)? - /// Mocked function for `trackMetric(deliveryID: String, event: Metric, deviceToken: String)`. Your opportunity to - /// return a mocked value and check result of mock in test code. + /// Mocked function for `trackMetric(deliveryID: String, event: Metric, deviceToken: String)`. Your opportunity to return a mocked value and check result of mock in test code. public func trackMetric(deliveryID: String, event: Metric, deviceToken: String) { mockCalled = true trackMetricCallsCount += 1 @@ -288,15 +275,9 @@ public class MessagingPushAPNInstanceMock: MessagingPushAPNInstance, Mock { } /// The arguments from the *last* time the function was called. - public private(set) var didReceiveNotificationRequestReceivedArguments: ( - request: UNNotificationRequest, - contentHandler: (UNNotificationContent) -> Void - )? + public private(set) var didReceiveNotificationRequestReceivedArguments: (request: UNNotificationRequest, contentHandler: (UNNotificationContent) -> Void)? /// Arguments from *all* of the times that the function was called. - public private(set) var didReceiveNotificationRequestReceivedInvocations: [( - request: UNNotificationRequest, - contentHandler: (UNNotificationContent) -> Void - )] = [] + public private(set) var didReceiveNotificationRequestReceivedInvocations: [(request: UNNotificationRequest, contentHandler: (UNNotificationContent) -> Void)] = [] /// Value to return from the mocked function. public var didReceiveNotificationRequestReturnValue: Bool! /** @@ -306,20 +287,14 @@ public class MessagingPushAPNInstanceMock: MessagingPushAPNInstance, Mock { */ public var didReceiveNotificationRequestClosure: ((UNNotificationRequest, (UNNotificationContent) -> Void) -> Bool)? - /// Mocked function for `didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping - /// (UNNotificationContent) -> Void)`. Your opportunity to return a mocked value and check result of mock in test - /// code. + /// Mocked function for `didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void)`. Your opportunity to return a mocked value and check result of mock in test code. @discardableResult - public func didReceive( - _ request: UNNotificationRequest, - withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void - ) -> Bool { + public func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) -> Bool { mockCalled = true didReceiveNotificationRequestCallsCount += 1 didReceiveNotificationRequestReceivedArguments = (request: request, contentHandler: contentHandler) didReceiveNotificationRequestReceivedInvocations.append((request: request, contentHandler: contentHandler)) - return didReceiveNotificationRequestClosure - .map { $0(request, contentHandler) } ?? didReceiveNotificationRequestReturnValue + return didReceiveNotificationRequestClosure.map { $0(request, contentHandler) } ?? didReceiveNotificationRequestReturnValue } #endif @@ -338,8 +313,7 @@ public class MessagingPushAPNInstanceMock: MessagingPushAPNInstance, Mock { */ public var serviceExtensionTimeWillExpireClosure: (() -> Void)? - /// Mocked function for `serviceExtensionTimeWillExpire()`. Your opportunity to return a mocked value and check - /// result of mock in test code. + /// Mocked function for `serviceExtensionTimeWillExpire()`. Your opportunity to return a mocked value and check result of mock in test code. public func serviceExtensionTimeWillExpire() { mockCalled = true serviceExtensionTimeWillExpireCallsCount += 1 diff --git a/Sources/MessagingPushFCM/autogenerated/AutoMockable.generated.swift b/Sources/MessagingPushFCM/autogenerated/AutoMockable.generated.swift index 9e2f4b495..a5fad2425 100644 --- a/Sources/MessagingPushFCM/autogenerated/AutoMockable.generated.swift +++ b/Sources/MessagingPushFCM/autogenerated/AutoMockable.generated.swift @@ -153,8 +153,7 @@ public class MessagingPushFCMInstanceMock: MessagingPushFCMInstance, Mock { */ public var registerDeviceTokenClosure: ((String?) -> Void)? - /// Mocked function for `registerDeviceToken(fcmToken: String?)`. Your opportunity to return a mocked value and - /// check result of mock in test code. + /// Mocked function for `registerDeviceToken(fcmToken: String?)`. Your opportunity to return a mocked value and check result of mock in test code. public func registerDeviceToken(fcmToken: String?) { mockCalled = true registerDeviceTokenCallsCount += 1 @@ -181,8 +180,7 @@ public class MessagingPushFCMInstanceMock: MessagingPushFCMInstance, Mock { */ public var didReceiveRegistrationTokenClosure: ((Any, String?) -> Void)? - /// Mocked function for `messaging(_ messaging: Any, didReceiveRegistrationToken fcmToken: String?)`. Your - /// opportunity to return a mocked value and check result of mock in test code. + /// Mocked function for `messaging(_ messaging: Any, didReceiveRegistrationToken fcmToken: String?)`. Your opportunity to return a mocked value and check result of mock in test code. public func messaging(_ messaging: Any, didReceiveRegistrationToken fcmToken: String?) { mockCalled = true didReceiveRegistrationTokenCallsCount += 1 @@ -203,17 +201,13 @@ public class MessagingPushFCMInstanceMock: MessagingPushFCMInstance, Mock { /// The arguments from the *last* time the function was called. public private(set) var didFailToRegisterForRemoteNotificationsReceivedArguments: (application: Any, error: Error)? /// Arguments from *all* of the times that the function was called. - public private(set) var didFailToRegisterForRemoteNotificationsReceivedInvocations: [( - application: Any, - error: Error - )] = [] + public private(set) var didFailToRegisterForRemoteNotificationsReceivedInvocations: [(application: Any, error: Error)] = [] /** Set closure to get called when function gets called. Great way to test logic or return a value for the function. */ public var didFailToRegisterForRemoteNotificationsClosure: ((Any, Error) -> Void)? - /// Mocked function for `application(_ application: Any, didFailToRegisterForRemoteNotificationsWithError error: - /// Error)`. Your opportunity to return a mocked value and check result of mock in test code. + /// Mocked function for `application(_ application: Any, didFailToRegisterForRemoteNotificationsWithError error: Error)`. Your opportunity to return a mocked value and check result of mock in test code. public func application(_ application: Any, didFailToRegisterForRemoteNotificationsWithError error: Error) { mockCalled = true didFailToRegisterForRemoteNotificationsCallsCount += 1 @@ -236,8 +230,7 @@ public class MessagingPushFCMInstanceMock: MessagingPushFCMInstance, Mock { */ public var deleteDeviceTokenClosure: (() -> Void)? - /// Mocked function for `deleteDeviceToken()`. Your opportunity to return a mocked value and check result of mock in - /// test code. + /// Mocked function for `deleteDeviceToken()`. Your opportunity to return a mocked value and check result of mock in test code. public func deleteDeviceToken() { mockCalled = true deleteDeviceTokenCallsCount += 1 @@ -256,15 +249,13 @@ public class MessagingPushFCMInstanceMock: MessagingPushFCMInstance, Mock { /// The arguments from the *last* time the function was called. public private(set) var trackMetricReceivedArguments: (deliveryID: String, event: Metric, deviceToken: String)? /// Arguments from *all* of the times that the function was called. - public private(set) var trackMetricReceivedInvocations: [(deliveryID: String, event: Metric, deviceToken: String)] = - [] + public private(set) var trackMetricReceivedInvocations: [(deliveryID: String, event: Metric, deviceToken: String)] = [] /** Set closure to get called when function gets called. Great way to test logic or return a value for the function. */ public var trackMetricClosure: ((String, Metric, String) -> Void)? - /// Mocked function for `trackMetric(deliveryID: String, event: Metric, deviceToken: String)`. Your opportunity to - /// return a mocked value and check result of mock in test code. + /// Mocked function for `trackMetric(deliveryID: String, event: Metric, deviceToken: String)`. Your opportunity to return a mocked value and check result of mock in test code. public func trackMetric(deliveryID: String, event: Metric, deviceToken: String) { mockCalled = true trackMetricCallsCount += 1 @@ -284,15 +275,9 @@ public class MessagingPushFCMInstanceMock: MessagingPushFCMInstance, Mock { } /// The arguments from the *last* time the function was called. - public private(set) var didReceiveNotificationRequestReceivedArguments: ( - request: UNNotificationRequest, - contentHandler: (UNNotificationContent) -> Void - )? + public private(set) var didReceiveNotificationRequestReceivedArguments: (request: UNNotificationRequest, contentHandler: (UNNotificationContent) -> Void)? /// Arguments from *all* of the times that the function was called. - public private(set) var didReceiveNotificationRequestReceivedInvocations: [( - request: UNNotificationRequest, - contentHandler: (UNNotificationContent) -> Void - )] = [] + public private(set) var didReceiveNotificationRequestReceivedInvocations: [(request: UNNotificationRequest, contentHandler: (UNNotificationContent) -> Void)] = [] /// Value to return from the mocked function. public var didReceiveNotificationRequestReturnValue: Bool! /** @@ -302,20 +287,14 @@ public class MessagingPushFCMInstanceMock: MessagingPushFCMInstance, Mock { */ public var didReceiveNotificationRequestClosure: ((UNNotificationRequest, (UNNotificationContent) -> Void) -> Bool)? - /// Mocked function for `didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping - /// (UNNotificationContent) -> Void)`. Your opportunity to return a mocked value and check result of mock in test - /// code. + /// Mocked function for `didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void)`. Your opportunity to return a mocked value and check result of mock in test code. @discardableResult - public func didReceive( - _ request: UNNotificationRequest, - withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void - ) -> Bool { + public func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) -> Bool { mockCalled = true didReceiveNotificationRequestCallsCount += 1 didReceiveNotificationRequestReceivedArguments = (request: request, contentHandler: contentHandler) didReceiveNotificationRequestReceivedInvocations.append((request: request, contentHandler: contentHandler)) - return didReceiveNotificationRequestClosure - .map { $0(request, contentHandler) } ?? didReceiveNotificationRequestReturnValue + return didReceiveNotificationRequestClosure.map { $0(request, contentHandler) } ?? didReceiveNotificationRequestReturnValue } #endif @@ -334,8 +313,7 @@ public class MessagingPushFCMInstanceMock: MessagingPushFCMInstance, Mock { */ public var serviceExtensionTimeWillExpireClosure: (() -> Void)? - /// Mocked function for `serviceExtensionTimeWillExpire()`. Your opportunity to return a mocked value and check - /// result of mock in test code. + /// Mocked function for `serviceExtensionTimeWillExpire()`. Your opportunity to return a mocked value and check result of mock in test code. public func serviceExtensionTimeWillExpire() { mockCalled = true serviceExtensionTimeWillExpireCallsCount += 1 diff --git a/Sources/Tracking/autogenerated/AutoDependencyInjection.generated.swift b/Sources/Tracking/autogenerated/AutoDependencyInjection.generated.swift index 406eacae6..f13c598a1 100644 --- a/Sources/Tracking/autogenerated/AutoDependencyInjection.generated.swift +++ b/Sources/Tracking/autogenerated/AutoDependencyInjection.generated.swift @@ -98,12 +98,6 @@ extension DIGraph { } private var newQueueRunnerHook: QueueRunnerHook { - TrackingQueueRunner( - siteId: siteId, - jsonAdapter: jsonAdapter, - logger: logger, - httpClient: httpClient, - sdkConfig: sdkConfig - ) + TrackingQueueRunner(siteId: siteId, jsonAdapter: jsonAdapter, logger: logger, httpClient: httpClient, sdkConfig: sdkConfig) } } diff --git a/Sources/Tracking/autogenerated/AutoMockable.generated.swift b/Sources/Tracking/autogenerated/AutoMockable.generated.swift index dff08b74f..a8779e1b4 100644 --- a/Sources/Tracking/autogenerated/AutoMockable.generated.swift +++ b/Sources/Tracking/autogenerated/AutoMockable.generated.swift @@ -115,8 +115,7 @@ internal class CleanupRepositoryMock: CleanupRepository, Mock { */ internal var cleanupClosure: (() -> Void)? - /// Mocked function for `cleanup()`. Your opportunity to return a mocked value and check result of mock in test - /// code. + /// Mocked function for `cleanup()`. Your opportunity to return a mocked value and check result of mock in test code. internal func cleanup() { mockCalled = true cleanupCallsCount += 1 @@ -318,8 +317,7 @@ public class CustomerIOInstanceMock: CustomerIOInstance, Mock { */ public var identifyClosure: ((String, [String: Any]) -> Void)? - /// Mocked function for `identify(identifier: String, body: [String: Any])`. Your opportunity to return a mocked - /// value and check result of mock in test code. + /// Mocked function for `identify(identifier: String, body: [String: Any])`. Your opportunity to return a mocked value and check result of mock in test code. public func identify(identifier: String, body: [String: Any]) { mockCalled = true identifyCallsCount += 1 @@ -339,8 +337,7 @@ public class CustomerIOInstanceMock: CustomerIOInstance, Mock { */ public var identifyEncodableClosure: ((String, AnyEncodable) -> Void)? - /// Mocked function for `identify(identifier: String, body: RequestBody)`. Your opportunity - /// to return a mocked value and check result of mock in test code. + /// Mocked function for `identify(identifier: String, body: RequestBody)`. Your opportunity to return a mocked value and check result of mock in test code. public func identify(identifier: String, body: RequestBody) { mockCalled = true identifyCallsCount += 1 @@ -363,8 +360,7 @@ public class CustomerIOInstanceMock: CustomerIOInstance, Mock { */ public var clearIdentifyClosure: (() -> Void)? - /// Mocked function for `clearIdentify()`. Your opportunity to return a mocked value and check result of mock in - /// test code. + /// Mocked function for `clearIdentify()`. Your opportunity to return a mocked value and check result of mock in test code. public func clearIdentify() { mockCalled = true clearIdentifyCallsCount += 1 @@ -389,8 +385,7 @@ public class CustomerIOInstanceMock: CustomerIOInstance, Mock { */ public var trackClosure: ((String, [String: Any]) -> Void)? - /// Mocked function for `track(name: String, data: [String: Any])`. Your opportunity to return a mocked value and - /// check result of mock in test code. + /// Mocked function for `track(name: String, data: [String: Any])`. Your opportunity to return a mocked value and check result of mock in test code. public func track(name: String, data: [String: Any]) { mockCalled = true trackCallsCount += 1 @@ -410,8 +405,7 @@ public class CustomerIOInstanceMock: CustomerIOInstance, Mock { */ public var trackEncodableClosure: ((String, AnyEncodable) -> Void)? - /// Mocked function for `track(name: String, data: RequestBody?)`. Your opportunity to - /// return a mocked value and check result of mock in test code. + /// Mocked function for `track(name: String, data: RequestBody?)`. Your opportunity to return a mocked value and check result of mock in test code. public func track(name: String, data: RequestBody?) { mockCalled = true trackCallsCount += 1 @@ -438,8 +432,7 @@ public class CustomerIOInstanceMock: CustomerIOInstance, Mock { */ public var screenClosure: ((String, [String: Any]) -> Void)? - /// Mocked function for `screen(name: String, data: [String: Any])`. Your opportunity to return a mocked value and - /// check result of mock in test code. + /// Mocked function for `screen(name: String, data: [String: Any])`. Your opportunity to return a mocked value and check result of mock in test code. public func screen(name: String, data: [String: Any]) { mockCalled = true screenCallsCount += 1 @@ -459,8 +452,7 @@ public class CustomerIOInstanceMock: CustomerIOInstance, Mock { */ public var screenEncodableClosure: ((String, AnyEncodable) -> Void)? - /// Mocked function for `screen(name: String, data: RequestBody?)`. Your opportunity to - /// return a mocked value and check result of mock in test code. + /// Mocked function for `screen(name: String, data: RequestBody?)`. Your opportunity to return a mocked value and check result of mock in test code. public func screen(name: String, data: RequestBody?) { mockCalled = true screenCallsCount += 1 @@ -487,8 +479,7 @@ public class CustomerIOInstanceMock: CustomerIOInstance, Mock { */ public var registerDeviceTokenClosure: ((String) -> Void)? - /// Mocked function for `registerDeviceToken(_ deviceToken: String)`. Your opportunity to return a mocked value and - /// check result of mock in test code. + /// Mocked function for `registerDeviceToken(_ deviceToken: String)`. Your opportunity to return a mocked value and check result of mock in test code. public func registerDeviceToken(_ deviceToken: String) { mockCalled = true registerDeviceTokenCallsCount += 1 @@ -511,8 +502,7 @@ public class CustomerIOInstanceMock: CustomerIOInstance, Mock { */ public var deleteDeviceTokenClosure: (() -> Void)? - /// Mocked function for `deleteDeviceToken()`. Your opportunity to return a mocked value and check result of mock in - /// test code. + /// Mocked function for `deleteDeviceToken()`. Your opportunity to return a mocked value and check result of mock in test code. public func deleteDeviceToken() { mockCalled = true deleteDeviceTokenCallsCount += 1 @@ -531,15 +521,13 @@ public class CustomerIOInstanceMock: CustomerIOInstance, Mock { /// The arguments from the *last* time the function was called. public private(set) var trackMetricReceivedArguments: (deliveryID: String, event: Metric, deviceToken: String)? /// Arguments from *all* of the times that the function was called. - public private(set) var trackMetricReceivedInvocations: [(deliveryID: String, event: Metric, deviceToken: String)] = - [] + public private(set) var trackMetricReceivedInvocations: [(deliveryID: String, event: Metric, deviceToken: String)] = [] /** Set closure to get called when function gets called. Great way to test logic or return a value for the function. */ public var trackMetricClosure: ((String, Metric, String) -> Void)? - /// Mocked function for `trackMetric(deliveryID: String, event: Metric, deviceToken: String)`. Your opportunity to - /// return a mocked value and check result of mock in test code. + /// Mocked function for `trackMetric(deliveryID: String, event: Metric, deviceToken: String)`. Your opportunity to return a mocked value and check result of mock in test code. public func trackMetric(deliveryID: String, event: Metric, deviceToken: String) { mockCalled = true trackMetricCallsCount += 1 @@ -590,8 +578,7 @@ internal class DeviceAttributesProviderMock: DeviceAttributesProvider, Mock { */ internal var getDefaultDeviceAttributesClosure: ((([String: Any]) -> Void) -> Void)? - /// Mocked function for `getDefaultDeviceAttributes(onComplete: @escaping ([String: Any]) -> Void)`. Your - /// opportunity to return a mocked value and check result of mock in test code. + /// Mocked function for `getDefaultDeviceAttributes(onComplete: @escaping ([String: Any]) -> Void)`. Your opportunity to return a mocked value and check result of mock in test code. internal func getDefaultDeviceAttributes(onComplete: @escaping ([String: Any]) -> Void) { mockCalled = true getDefaultDeviceAttributesCallsCount += 1 diff --git a/Tests/MessagingInApp/APITest.swift b/Tests/MessagingInApp/APITest.swift index 2634f4c29..1aa0f236a 100644 --- a/Tests/MessagingInApp/APITest.swift +++ b/Tests/MessagingInApp/APITest.swift @@ -28,7 +28,6 @@ class MessagingInAppAPITest: UnitTest { extension MessagingInAppAPITest: InAppEventListener { func messageShown(message: InAppMessage) { // make sure all properties of InAppMessage are accessible - _ = message.instanceId _ = message.messageId _ = message.deliveryId } @@ -37,5 +36,5 @@ extension MessagingInAppAPITest: InAppEventListener { func errorWithMessage(message: InAppMessage) {} - func messageActionTaken(message: InAppMessage, currentRoute: String, action: String, name: String) {} + func messageActionTaken(message: InAppMessage, action: String, name: String) {} } diff --git a/Tests/MessagingInApp/MessagingInAppImplementationTest.swift b/Tests/MessagingInApp/MessagingInAppImplementationTest.swift index 05ebcfc83..9d4349a53 100644 --- a/Tests/MessagingInApp/MessagingInAppImplementationTest.swift +++ b/Tests/MessagingInApp/MessagingInAppImplementationTest.swift @@ -105,7 +105,6 @@ class MessagingInAppImplementationTest: UnitTest { ) XCTAssertEqual(eventListenerMock.messageActionTakenCallsCount, 1) XCTAssertEqual(eventListenerMock.messageActionTakenReceivedArguments?.message, expectedInAppMessage) - XCTAssertEqual(eventListenerMock.messageActionTakenReceivedArguments?.currentRoute, givenCurrentRoute) XCTAssertEqual(eventListenerMock.messageActionTakenReceivedArguments?.action, givenAction) XCTAssertEqual(eventListenerMock.messageActionTakenReceivedArguments?.name, givenName) } From da93b71221cdb68e824b9c38d468429c7df67204 Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Wed, 18 Jan 2023 10:06:32 -0600 Subject: [PATCH 08/14] test when sdk not initialized yet --- Sources/MessagingInApp/MessagingInApp.swift | 4 ++-- Sources/MessagingPush/MessagingPush.swift | 2 +- Sources/Tracking/ModuleTopLevelObject.swift | 2 +- Tests/MessagingInApp/MessagingInAppTest.swift | 12 +++++++++++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Sources/MessagingInApp/MessagingInApp.swift b/Sources/MessagingInApp/MessagingInApp.swift index 28ca1237c..70553d2ad 100644 --- a/Sources/MessagingInApp/MessagingInApp.swift +++ b/Sources/MessagingInApp/MessagingInApp.swift @@ -12,7 +12,7 @@ public protocol MessagingInAppInstance: AutoMockable { public class MessagingInApp: ModuleTopLevelObject, MessagingInAppInstance { @Atomic public private(set) static var shared = MessagingInApp() - override internal init(implementation: MessagingInAppInstance, sdkInitializedUtil: SdkInitializedUtil) { + override internal init(implementation: MessagingInAppInstance?, sdkInitializedUtil: SdkInitializedUtil) { super.init(implementation: implementation, sdkInitializedUtil: sdkInitializedUtil) } @@ -27,7 +27,7 @@ public class MessagingInApp: ModuleTopLevelObject, Messa } // testing constructor - internal static func initialize(organizationId: String, eventListener: InAppEventListener?, implementation: MessagingInAppInstance, sdkInitializedUtil: SdkInitializedUtil) { + internal static func initialize(organizationId: String, eventListener: InAppEventListener?, implementation: MessagingInAppInstance?, sdkInitializedUtil: SdkInitializedUtil) { Self.shared = MessagingInApp(implementation: implementation, sdkInitializedUtil: sdkInitializedUtil) if let eventListener = eventListener { diff --git a/Sources/MessagingPush/MessagingPush.swift b/Sources/MessagingPush/MessagingPush.swift index 49c562e89..00f233875 100644 --- a/Sources/MessagingPush/MessagingPush.swift +++ b/Sources/MessagingPush/MessagingPush.swift @@ -14,7 +14,7 @@ public class MessagingPush: ModuleTopLevelObject, Messagi @Atomic public private(set) static var shared = MessagingPush() // testing constructor - override internal init(implementation: MessagingPushInstance, sdkInitializedUtil: SdkInitializedUtil) { + override internal init(implementation: MessagingPushInstance?, sdkInitializedUtil: SdkInitializedUtil) { super.init(implementation: implementation, sdkInitializedUtil: sdkInitializedUtil) } diff --git a/Sources/Tracking/ModuleTopLevelObject.swift b/Sources/Tracking/ModuleTopLevelObject.swift index 7b4a8c108..c39ceeb7b 100644 --- a/Sources/Tracking/ModuleTopLevelObject.swift +++ b/Sources/Tracking/ModuleTopLevelObject.swift @@ -17,7 +17,7 @@ open class ModuleTopLevelObject { private let sdkInitializedUtil: SdkInitializedUtil // for writing tests - public init(implementation: ImplementationClass, sdkInitializedUtil: SdkInitializedUtil) { + public init(implementation: ImplementationClass?, sdkInitializedUtil: SdkInitializedUtil) { self.alreadyCreatedImplementation = implementation self.sdkInitializedUtil = sdkInitializedUtil } diff --git a/Tests/MessagingInApp/MessagingInAppTest.swift b/Tests/MessagingInApp/MessagingInAppTest.swift index 21b4b845d..cbbfd5762 100644 --- a/Tests/MessagingInApp/MessagingInAppTest.swift +++ b/Tests/MessagingInApp/MessagingInAppTest.swift @@ -16,7 +16,8 @@ class MessagingInAppTest: UnitTest { MessagingInApp.resetSharedInstance() - sdkInitializedUtilMock.postInitializedData = (siteId: testSiteId, diGraph: diGraph) + // This is where we inject the DI graph into our tests + sdkInitializedUtilMock.underlyingPostInitializedData = (siteId: testSiteId, diGraph: diGraph) diGraph.override(value: hooksMock, forType: HooksManager.self) } @@ -34,4 +35,13 @@ class MessagingInAppTest: UnitTest { XCTAssertEqual(hooksMock.addCallsCount, 1) XCTAssertEqual(hooksMock.addReceivedArguments?.key, .messagingInApp) } + + func test_initialize_sdkNotInitialized_expectInAppModuleNotInitialized() { + sdkInitializedUtilMock.underlyingPostInitializedData = nil // the SDK is no longer initialized + + MessagingInApp.initialize(organizationId: String.random, eventListener: nil, implementation: nil, sdkInitializedUtil: sdkInitializedUtilMock) + + XCTAssertFalse(hooksMock.addCalled) + XCTAssertFalse(hooksMock.mockCalled) + } } From a3712017abcf073f712215d33f1ee94ddb37a16d Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Wed, 18 Jan 2023 10:11:45 -0600 Subject: [PATCH 09/14] add note [skip ci] --- Sources/Tracking/ModuleTopLevelObject.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/Tracking/ModuleTopLevelObject.swift b/Sources/Tracking/ModuleTopLevelObject.swift index c39ceeb7b..41d1f1009 100644 --- a/Sources/Tracking/ModuleTopLevelObject.swift +++ b/Sources/Tracking/ModuleTopLevelObject.swift @@ -17,6 +17,7 @@ open class ModuleTopLevelObject { private let sdkInitializedUtil: SdkInitializedUtil // for writing tests + // provide a nil implementation if you want `sdkInitializedUtil` logic to run and real instance of implementation to run in tests public init(implementation: ImplementationClass?, sdkInitializedUtil: SdkInitializedUtil) { self.alreadyCreatedImplementation = implementation self.sdkInitializedUtil = sdkInitializedUtil From c7897d0c3c9405b4e9dbbe666db417238b59f884 Mon Sep 17 00:00:00 2001 From: Shahroz Khan Date: Wed, 25 Jan 2023 07:31:26 +0500 Subject: [PATCH 10/14] fix: gist set user token incase identifier exists (#253) --- .../MessagingInAppImplementation.swift | 9 +++++++++ .../MessagingInAppImplementationTest.swift | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/Sources/MessagingInApp/MessagingInAppImplementation.swift b/Sources/MessagingInApp/MessagingInAppImplementation.swift index fd6ca19ba..ca8aaf9fc 100644 --- a/Sources/MessagingInApp/MessagingInAppImplementation.swift +++ b/Sources/MessagingInApp/MessagingInAppImplementation.swift @@ -10,15 +10,24 @@ internal class MessagingInAppImplementation: MessagingInAppInstance { private var inAppProvider: InAppProvider private var eventListener: InAppEventListener? + private var profileStore: ProfileStore? + init(diGraph: DIGraph) { self.logger = diGraph.logger self.queue = diGraph.queue self.jsonAdapter = diGraph.jsonAdapter self.inAppProvider = diGraph.inAppProvider + self.profileStore = diGraph.profileStore } func initialize(organizationId: String) { inAppProvider.initialize(organizationId: organizationId, delegate: self) + + // if identifier is already present, set the userToken again so in case if the customer was already identified and + // module was added later on, we can notify gist about it. + if let identifier = profileStore?.identifier { + inAppProvider.setProfileIdentifier(identifier) + } } func initialize(organizationId: String, eventListener: InAppEventListener) { diff --git a/Tests/MessagingInApp/MessagingInAppImplementationTest.swift b/Tests/MessagingInApp/MessagingInAppImplementationTest.swift index 9d4349a53..1e509fb4b 100644 --- a/Tests/MessagingInApp/MessagingInAppImplementationTest.swift +++ b/Tests/MessagingInApp/MessagingInAppImplementationTest.swift @@ -1,5 +1,6 @@ @testable import CioMessagingInApp @testable import CioTracking +@testable import Common import Foundation import Gist import SharedTests @@ -10,11 +11,13 @@ class MessagingInAppImplementationTest: UnitTest { private let inAppProviderMock = InAppProviderMock() private let eventListenerMock = InAppEventListenerMock() + private let profileStoreMock = ProfileStoreMock() override func setUp() { super.setUp() diGraph.override(value: inAppProviderMock, forType: InAppProvider.self) + diGraph.override(value: profileStoreMock, forType: ProfileStore.self) messagingInApp = MessagingInAppImplementation(diGraph: diGraph) messagingInApp.initialize(organizationId: .random, eventListener: eventListenerMock) @@ -31,6 +34,20 @@ class MessagingInAppImplementationTest: UnitTest { XCTAssertTrue(inAppProviderMock.initializeCalled) } + func test_initialize_givenIdentifier_expectGistSetProfileIdentifier() { + let givenProfileIdentifiedInSdk = String.random + + profileStoreMock.identifier = givenProfileIdentifiedInSdk + + let givenId = String.random + let instance = MessagingInAppImplementation(diGraph: diGraph) + instance.initialize(organizationId: givenId) + + XCTAssertTrue(inAppProviderMock.initializeCalled) + XCTAssertTrue(inAppProviderMock.setProfileIdentifierCalled) + XCTAssertEqual(inAppProviderMock.setProfileIdentifierReceivedArguments, givenProfileIdentifiedInSdk) + } + func test_initialize_givenOrganizationId_givenEventListener_expectInitializeGistSDK() { let givenId = String.random From 6b9554b1f7cf28f2d0d5d88551a061bc8fa47c19 Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Wed, 25 Jan 2023 08:41:20 -0600 Subject: [PATCH 11/14] docs: add docs from pr review --- Sources/MessagingInApp/MessagingInApp.swift | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sources/MessagingInApp/MessagingInApp.swift b/Sources/MessagingInApp/MessagingInApp.swift index 70553d2ad..1af78bcc0 100644 --- a/Sources/MessagingInApp/MessagingInApp.swift +++ b/Sources/MessagingInApp/MessagingInApp.swift @@ -37,7 +37,12 @@ public class MessagingInApp: ModuleTopLevelObject, Messa } } - // Initialize SDK module + // MARK: static initialized functions for customers. + + // static functions are identical to initialize functions in InAppInstance protocol to try and make a more convenient + // API for customers. Customers can use `MessagingInApp.initialize(...)` instead of `MessagingInApp.shared.initialize(...)`. + // Trying to follow the same API as `CustomerIO` class with `initialize()`. + public static func initialize(organizationId: String) { Self.shared.initialize(organizationId: organizationId) } @@ -46,6 +51,10 @@ public class MessagingInApp: ModuleTopLevelObject, Messa Self.shared.initialize(organizationId: organizationId, eventListener: eventListener) } + // MARK: initialize functions to initialize module. + + // Multiple initialize functions to inherit the InAppInstance protocol which contains multiple initialize functions. + public func initialize(organizationId: String) { guard let implementation = implementation else { sdkNotInitializedAlert("CustomerIO class has not yet been initialized. Request to initialize the in-app module has been ignored.") From 40fa85610753d94a5e178d0e2131c091a1f2f285 Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Fri, 27 Jan 2023 13:31:36 -0600 Subject: [PATCH 12/14] refactor: remove duplicate code for initialize --- Sources/MessagingInApp/MessagingInApp.swift | 19 ++++++++++--------- Tests/MessagingInApp/MessagingInAppTest.swift | 5 +++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Sources/MessagingInApp/MessagingInApp.swift b/Sources/MessagingInApp/MessagingInApp.swift index 1af78bcc0..e7e9acf22 100644 --- a/Sources/MessagingInApp/MessagingInApp.swift +++ b/Sources/MessagingInApp/MessagingInApp.swift @@ -56,17 +56,14 @@ public class MessagingInApp: ModuleTopLevelObject, Messa // Multiple initialize functions to inherit the InAppInstance protocol which contains multiple initialize functions. public func initialize(organizationId: String) { - guard let implementation = implementation else { - sdkNotInitializedAlert("CustomerIO class has not yet been initialized. Request to initialize the in-app module has been ignored.") - return - } - - initialize() - - implementation.initialize(organizationId: organizationId) + commonInitialize(organizationId: organizationId, eventListener: nil) } public func initialize(organizationId: String, eventListener: InAppEventListener) { + commonInitialize(organizationId: organizationId, eventListener: eventListener) + } + + private func commonInitialize(organizationId: String, eventListener: InAppEventListener?) { guard let implementation = implementation else { sdkNotInitializedAlert("CustomerIO class has not yet been initialized. Request to initialize the in-app module has been ignored.") return @@ -74,7 +71,11 @@ public class MessagingInApp: ModuleTopLevelObject, Messa initialize() - implementation.initialize(organizationId: organizationId, eventListener: eventListener) + if let eventListener = eventListener { + implementation.initialize(organizationId: organizationId, eventListener: eventListener) + } else { + implementation.initialize(organizationId: organizationId) + } } override public func inititlize(diGraph: DIGraph) { diff --git a/Tests/MessagingInApp/MessagingInAppTest.swift b/Tests/MessagingInApp/MessagingInAppTest.swift index cbbfd5762..3ca8d017e 100644 --- a/Tests/MessagingInApp/MessagingInAppTest.swift +++ b/Tests/MessagingInApp/MessagingInAppTest.swift @@ -27,6 +27,8 @@ class MessagingInAppTest: UnitTest { XCTAssertEqual(hooksMock.addCallsCount, 1) XCTAssertEqual(hooksMock.addReceivedArguments?.key, .messagingInApp) + XCTAssertEqual(implementationMock.initializeCallsCount, 1) + XCTAssertEqual(implementationMock.initializeEventListenerCallsCount, 0) } func test_initialize_givenEventListener_expectCallModuleInitializeCode() { @@ -34,6 +36,8 @@ class MessagingInAppTest: UnitTest { XCTAssertEqual(hooksMock.addCallsCount, 1) XCTAssertEqual(hooksMock.addReceivedArguments?.key, .messagingInApp) + XCTAssertEqual(implementationMock.initializeCallsCount, 0) + XCTAssertEqual(implementationMock.initializeEventListenerCallsCount, 1) } func test_initialize_sdkNotInitialized_expectInAppModuleNotInitialized() { @@ -43,5 +47,6 @@ class MessagingInAppTest: UnitTest { XCTAssertFalse(hooksMock.addCalled) XCTAssertFalse(hooksMock.mockCalled) + XCTAssertFalse(implementationMock.mockCalled) } } From f0e429cfe26a89be2c767b7ef77386aa0bc682b0 Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Fri, 27 Jan 2023 13:58:57 -0600 Subject: [PATCH 13/14] add resolved package --- Package.resolved | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Package.resolved b/Package.resolved index 5d7c7ac57..85ff9d73a 100644 --- a/Package.resolved +++ b/Package.resolved @@ -6,8 +6,8 @@ "repositoryURL": "https://gitlab.com/bourbonltd/gist-apple.git", "state": { "branch": null, - "revision": "2b1f647d96038027c3018e9bfff6cb27e944bf09", - "version": "2.2.1" + "revision": "408077c633807dc00fbce263cf513f69ab40a75b", + "version": "2.2.2" } } ] From cbfff6277a73bade920390ef0617ab121eca0927 Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Fri, 27 Jan 2023 14:03:26 -0600 Subject: [PATCH 14/14] update from code review --- Sources/MessagingInApp/MessagingInAppImplementation.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/MessagingInApp/MessagingInAppImplementation.swift b/Sources/MessagingInApp/MessagingInAppImplementation.swift index ca8aaf9fc..bd949e908 100644 --- a/Sources/MessagingInApp/MessagingInAppImplementation.swift +++ b/Sources/MessagingInApp/MessagingInAppImplementation.swift @@ -8,9 +8,9 @@ internal class MessagingInAppImplementation: MessagingInAppInstance { private var queue: Queue private var jsonAdapter: JsonAdapter private var inAppProvider: InAppProvider - private var eventListener: InAppEventListener? + private var profileStore: ProfileStore - private var profileStore: ProfileStore? + private var eventListener: InAppEventListener? init(diGraph: DIGraph) { self.logger = diGraph.logger @@ -25,7 +25,7 @@ internal class MessagingInAppImplementation: MessagingInAppInstance { // if identifier is already present, set the userToken again so in case if the customer was already identified and // module was added later on, we can notify gist about it. - if let identifier = profileStore?.identifier { + if let identifier = profileStore.identifier { inAppProvider.setProfileIdentifier(identifier) } }