Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: in-app dismiss message #320

Merged
merged 7 commits into from May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 11 additions & 11 deletions Sources/Common/autogenerated/AutoMockable.generated.swift
Expand Up @@ -134,7 +134,7 @@ public class DeviceInfoMock: DeviceInfo, Mock {
When setter of the property called, the value given to setter is set here.
When the getter of the property called, the value set here will be returned. Your chance to mock the property.
*/
public var underlyingDeviceModel: String? = nil
public var underlyingDeviceModel: String?
/// `true` if the getter or setter of property is called at least once.
public var deviceModelCalled: Bool {
deviceModelGetCalled || deviceModelSetCalled
Expand Down Expand Up @@ -170,7 +170,7 @@ public class DeviceInfoMock: DeviceInfo, Mock {
When setter of the property called, the value given to setter is set here.
When the getter of the property called, the value set here will be returned. Your chance to mock the property.
*/
public var underlyingOsVersion: String? = nil
public var underlyingOsVersion: String?
/// `true` if the getter or setter of property is called at least once.
public var osVersionCalled: Bool {
osVersionGetCalled || osVersionSetCalled
Expand Down Expand Up @@ -206,7 +206,7 @@ public class DeviceInfoMock: DeviceInfo, Mock {
When setter of the property called, the value given to setter is set here.
When the getter of the property called, the value set here will be returned. Your chance to mock the property.
*/
public var underlyingOsName: String? = nil
public var underlyingOsName: String?
/// `true` if the getter or setter of property is called at least once.
public var osNameCalled: Bool {
osNameGetCalled || osNameSetCalled
Expand Down Expand Up @@ -494,7 +494,7 @@ internal class DeviceMetricsGrabberMock: DeviceMetricsGrabber, Mock {
When setter of the property called, the value given to setter is set here.
When the getter of the property called, the value set here will be returned. Your chance to mock the property.
*/
internal var underlyingAppBundleId: String? = nil
internal var underlyingAppBundleId: String?
/// `true` if the getter or setter of property is called at least once.
internal var appBundleIdCalled: Bool {
appBundleIdGetCalled || appBundleIdSetCalled
Expand Down Expand Up @@ -679,7 +679,7 @@ public class GlobalDataStoreMock: GlobalDataStore, Mock {
When setter of the property called, the value given to setter is set here.
When the getter of the property called, the value set here will be returned. Your chance to mock the property.
*/
public var underlyingPushDeviceToken: String? = nil
public var underlyingPushDeviceToken: String?
/// `true` if the getter or setter of property is called at least once.
public var pushDeviceTokenCalled: Bool {
pushDeviceTokenGetCalled || pushDeviceTokenSetCalled
Expand Down Expand Up @@ -715,7 +715,7 @@ public class GlobalDataStoreMock: GlobalDataStore, Mock {
When setter of the property called, the value given to setter is set here.
When the getter of the property called, the value set here will be returned. Your chance to mock the property.
*/
public var underlyingHttpRequestsPauseEnds: Date? = nil
public var underlyingHttpRequestsPauseEnds: Date?
/// `true` if the getter or setter of property is called at least once.
public var httpRequestsPauseEndsCalled: Bool {
httpRequestsPauseEndsGetCalled || httpRequestsPauseEndsSetCalled
Expand Down Expand Up @@ -1163,7 +1163,7 @@ internal class HttpRetryPolicyMock: HttpRetryPolicy, Mock {
When setter of the property called, the value given to setter is set here.
When the getter of the property called, the value set here will be returned. Your chance to mock the property.
*/
internal var underlyingNextSleepTime: Seconds? = nil
internal var underlyingNextSleepTime: Seconds?
/// `true` if the getter or setter of property is called at least once.
internal var nextSleepTimeCalled: Bool {
nextSleepTimeGetCalled || nextSleepTimeSetCalled
Expand Down Expand Up @@ -1336,7 +1336,7 @@ public class ModuleHookProviderMock: ModuleHookProvider, Mock {
When setter of the property called, the value given to setter is set here.
When the getter of the property called, the value set here will be returned. Your chance to mock the property.
*/
public var underlyingProfileIdentifyHook: ProfileIdentifyHook? = nil
public var underlyingProfileIdentifyHook: ProfileIdentifyHook?
/// `true` if the getter or setter of property is called at least once.
public var profileIdentifyHookCalled: Bool {
profileIdentifyHookGetCalled || profileIdentifyHookSetCalled
Expand Down Expand Up @@ -1372,7 +1372,7 @@ public class ModuleHookProviderMock: ModuleHookProvider, Mock {
When setter of the property called, the value given to setter is set here.
When the getter of the property called, the value set here will be returned. Your chance to mock the property.
*/
public var underlyingQueueRunnerHook: QueueRunnerHook? = nil
public var underlyingQueueRunnerHook: QueueRunnerHook?
/// `true` if the getter or setter of property is called at least once.
public var queueRunnerHookCalled: Bool {
queueRunnerHookGetCalled || queueRunnerHookSetCalled
Expand Down Expand Up @@ -1408,7 +1408,7 @@ public class ModuleHookProviderMock: ModuleHookProvider, Mock {
When setter of the property called, the value given to setter is set here.
When the getter of the property called, the value set here will be returned. Your chance to mock the property.
*/
public var underlyingScreenTrackingHook: ScreenTrackingHook? = nil
public var underlyingScreenTrackingHook: ScreenTrackingHook?
/// `true` if the getter or setter of property is called at least once.
public var screenTrackingHookCalled: Bool {
screenTrackingHookGetCalled || screenTrackingHookSetCalled
Expand Down Expand Up @@ -1587,7 +1587,7 @@ public class ProfileStoreMock: ProfileStore, Mock {
When setter of the property called, the value given to setter is set here.
When the getter of the property called, the value set here will be returned. Your chance to mock the property.
*/
public var underlyingIdentifier: String? = nil
public var underlyingIdentifier: String?
/// `true` if the getter or setter of property is called at least once.
public var identifierCalled: Bool {
identifierGetCalled || identifierSetCalled
Expand Down
7 changes: 7 additions & 0 deletions Sources/MessagingInApp/MessagingInApp.swift
Expand Up @@ -12,6 +12,8 @@ public protocol MessagingInAppInstance: AutoMockable {
@available(*, deprecated, message: "Parameter organizationId no longer being used. Remove the parameter from your function call to migrate to new function.")
// sourcery:Name=initializeOrganizationId
func initialize(organizationId: String)

func dismissMessage()
ami-aman marked this conversation as resolved.
Show resolved Hide resolved
}

public class MessagingInApp: ModuleTopLevelObject<MessagingInAppInstance>, MessagingInAppInstance {
Expand Down Expand Up @@ -102,4 +104,9 @@ public class MessagingInApp: ModuleTopLevelObject<MessagingInAppInstance>, Messa
override public func getImplementationInstance(diGraph: DIGraph) -> MessagingInAppInstance {
MessagingInAppImplementation(diGraph: diGraph)
}

// Dismiss in-app message
public func dismissMessage() {
implementation?.dismissMessage()
}
ami-aman marked this conversation as resolved.
Show resolved Hide resolved
}
5 changes: 5 additions & 0 deletions Sources/MessagingInApp/MessagingInAppImplementation.swift
Expand Up @@ -42,6 +42,11 @@ internal class MessagingInAppImplementation: MessagingInAppInstance {
// Functions deprecated but need to exist for `MessagingInAppInstance` protocol.
// Do not call these functions but non-deprecated ones.
func initialize(organizationId: String) {}

// Dismiss in-app message
func dismissMessage() {
inAppProvider.dismissMessage()
}
}

extension MessagingInAppImplementation: ProfileIdentifyHook {
Expand Down
5 changes: 5 additions & 0 deletions Sources/MessagingInApp/Provider/InAppProvider.swift
Expand Up @@ -8,6 +8,7 @@ internal protocol InAppProvider: AutoMockable {
func setProfileIdentifier(_ id: String)
func clearIdentify()
func setRoute(_ route: String)
func dismissMessage()
}

// sourcery: InjectRegister = "InAppProvider"
Expand All @@ -28,4 +29,8 @@ internal class GistInAppProvider: InAppProvider {
func setRoute(_ route: String) {
Gist.shared.setCurrentRoute(route)
}

func dismissMessage() {
Gist.shared.dismissMessage()
}
}
48 changes: 48 additions & 0 deletions Sources/MessagingInApp/autogenerated/AutoMockable.generated.swift
Expand Up @@ -262,6 +262,9 @@ internal class InAppProviderMock: InAppProvider, Mock {
setRouteReceivedArguments = nil
setRouteReceivedInvocations = []

mockCalled = false // do last as resetting properties above can make this true
dismissMessageCallsCount = 0

mockCalled = false // do last as resetting properties above can make this true
}

Expand Down Expand Up @@ -366,6 +369,27 @@ internal class InAppProviderMock: InAppProvider, Mock {
setRouteReceivedInvocations.append(route)
setRouteClosure?(route)
}

// MARK: - dismissMessage

/// Number of times the function was called.
internal private(set) var dismissMessageCallsCount = 0
/// `true` if the function was ever called.
internal var dismissMessageCalled: Bool {
dismissMessageCallsCount > 0
}

/**
Set closure to get called when function gets called. Great way to test logic or return a value for the function.
*/
internal var dismissMessageClosure: (() -> Void)?

/// Mocked function for `dismissMessage()`. Your opportunity to return a mocked value and check result of mock in test code.
internal func dismissMessage() {
mockCalled = true
dismissMessageCallsCount += 1
dismissMessageClosure?()
}
}

/**
Expand Down Expand Up @@ -396,6 +420,9 @@ public class MessagingInAppInstanceMock: MessagingInAppInstance, Mock {
initializeOrganizationIdReceivedArguments = nil
initializeOrganizationIdReceivedInvocations = []

mockCalled = false // do last as resetting properties above can make this true
dismissMessageCallsCount = 0

mockCalled = false // do last as resetting properties above can make this true
}

Expand Down Expand Up @@ -474,6 +501,27 @@ public class MessagingInAppInstanceMock: MessagingInAppInstance, Mock {
initializeOrganizationIdReceivedInvocations.append(organizationId)
initializeOrganizationIdClosure?(organizationId)
}

// MARK: - dismissMessage

/// Number of times the function was called.
public private(set) var dismissMessageCallsCount = 0
/// `true` if the function was ever called.
public var dismissMessageCalled: Bool {
dismissMessageCallsCount > 0
}

/**
Set closure to get called when function gets called. Great way to test logic or return a value for the function.
*/
public var dismissMessageClosure: (() -> Void)?

/// Mocked function for `dismissMessage()`. Your opportunity to return a mocked value and check result of mock in test code.
public func dismissMessage() {
mockCalled = true
dismissMessageCallsCount += 1
dismissMessageClosure?()
}
}

// swiftlint:enable all
8 changes: 4 additions & 4 deletions Sources/Tracking/autogenerated/AutoMockable.generated.swift
Expand Up @@ -142,7 +142,7 @@ public class CustomerIOInstanceMock: CustomerIOInstance, Mock {
When setter of the property called, the value given to setter is set here.
When the getter of the property called, the value set here will be returned. Your chance to mock the property.
*/
public var underlyingSiteId: String? = nil
public var underlyingSiteId: String?
/// `true` if the getter or setter of property is called at least once.
public var siteIdCalled: Bool {
siteIdGetCalled || siteIdSetCalled
Expand Down Expand Up @@ -178,7 +178,7 @@ public class CustomerIOInstanceMock: CustomerIOInstance, Mock {
When setter of the property called, the value given to setter is set here.
When the getter of the property called, the value set here will be returned. Your chance to mock the property.
*/
public var underlyingConfig: SdkConfig? = nil
public var underlyingConfig: SdkConfig?
/// `true` if the getter or setter of property is called at least once.
public var configCalled: Bool {
configGetCalled || configSetCalled
Expand Down Expand Up @@ -646,7 +646,7 @@ public class SdkInitializedUtilMock: SdkInitializedUtil, Mock {
When setter of the property called, the value given to setter is set here.
When the getter of the property called, the value set here will be returned. Your chance to mock the property.
*/
public var underlyingCustomerio: CustomerIO? = nil
public var underlyingCustomerio: CustomerIO?
/// `true` if the getter or setter of property is called at least once.
public var customerioCalled: Bool {
customerioGetCalled || customerioSetCalled
Expand Down Expand Up @@ -718,7 +718,7 @@ public class SdkInitializedUtilMock: SdkInitializedUtil, Mock {
When setter of the property called, the value given to setter is set here.
When the getter of the property called, the value set here will be returned. Your chance to mock the property.
*/
public var underlyingPostInitializedData: (siteId: String, diGraph: DIGraph)? = nil
public var underlyingPostInitializedData: (siteId: String, diGraph: DIGraph)?
/// `true` if the getter or setter of property is called at least once.
public var postInitializedDataCalled: Bool {
postInitializedDataGetCalled || postInitializedDataSetCalled
Expand Down
17 changes: 17 additions & 0 deletions Tests/MessagingInApp/MessagingInAppImplementationTest.swift
Expand Up @@ -234,4 +234,21 @@ class MessagingInAppImplementationTest: UnitTest {
XCTAssertEqual(backgroundQueueMock.addTrackInAppDeliveryTaskReceivedArguments?.event, .clicked)
XCTAssertEqual(backgroundQueueMock.addTrackInAppDeliveryTaskReceivedArguments?.metaData, givenMetaData)
}

func test_dismissMessage_givenNoInAppMessage_expectNoError() {
// Dismiss in-app message
XCTAssertFalse(inAppProviderMock.dismissMessageCalled)
messagingInApp.dismissMessage()
XCTAssertEqual(inAppProviderMock.dismissMessageCallsCount, 1)
}

func test_dismissMessage_givenInAppMessage_expectNoError() {
let givenGistMessage = Message.random
_ = InAppMessage(gistMessage: givenGistMessage)

// Dismiss in-app message when an in-app message is shown on screen
XCTAssertFalse(inAppProviderMock.dismissMessageCalled)
messagingInApp.dismissMessage()
XCTAssertEqual(inAppProviderMock.dismissMessageCallsCount, 1)
}
}