-
Notifications
You must be signed in to change notification settings - Fork 12
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
Allowing opened push event to be transmitted when SDK is not initialized #181
Changes from all commits
e721e3c
30492c6
e147195
fa9293f
4e1dc18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,7 +116,7 @@ class StateManagementEdgeCaseTests: XCTestCase { | |
// MARK: - Set Email | ||
|
||
@MainActor | ||
func testSetEmailUninitialized() async throws { | ||
func testSetEmailUninitializedDoesNotAddToPendingRequest() async throws { | ||
let expection = XCTestExpectation(description: "fatal error expected") | ||
environment.emitDeveloperWarning = { _ in | ||
// Would really fatalError - not happening because we can't do that in tests so we fake it. | ||
|
@@ -168,7 +168,7 @@ class StateManagementEdgeCaseTests: XCTestCase { | |
// MARK: - Set External Id | ||
|
||
@MainActor | ||
func testSetExternalIdUninitialized() async throws { | ||
func testSetExternalIdUninitializedDoesNotAddToPendingRequest() async throws { | ||
let apiKey = "fake-key" | ||
let initialState = KlaviyoState(apiKey: apiKey, | ||
anonymousId: environment.analytics.uuid().uuidString, | ||
|
@@ -213,7 +213,7 @@ class StateManagementEdgeCaseTests: XCTestCase { | |
// MARK: - Set Phone number | ||
|
||
@MainActor | ||
func testSetPhoneNumberUninitialized() async throws { | ||
func testSetPhoneNumberUninitializedDoesNotAddToPendingRequest() async throws { | ||
let apiKey = "fake-key" | ||
let initialState = KlaviyoState(apiKey: apiKey, | ||
anonymousId: environment.analytics.uuid().uuidString, | ||
|
@@ -257,7 +257,7 @@ class StateManagementEdgeCaseTests: XCTestCase { | |
// MARK: - Set Push Token | ||
|
||
@MainActor | ||
func testSetPushTokenUninitialized() async throws { | ||
func testSetPushTokenUninitializedDoesNotAddToPendingRequest() async throws { | ||
let apiKey = "fake-key" | ||
let initialState = KlaviyoState(apiKey: apiKey, | ||
anonymousId: environment.analytics.uuid().uuidString, | ||
|
@@ -369,15 +369,30 @@ class StateManagementEdgeCaseTests: XCTestCase { | |
// MARK: - set enqueue event uninitialized | ||
|
||
@MainActor | ||
func testEnqueueEventUninitialized() async throws { | ||
func testOpenedPushEventUninitializedAddsToPendingRequests() async throws { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests opened push event is added to pending requests when SDK isn't initialized. |
||
let store = TestStore(initialState: .init(queue: []), reducer: KlaviyoReducer()) | ||
let event = Event(name: .OpenedPush) | ||
_ = await store.send(.enqueueEvent(event)) { | ||
$0.pendingRequests = [.event(event)] | ||
} | ||
} | ||
|
||
@MainActor | ||
func testEnqueueNonOpenedPushEventUninitializedDoesNotAddToPendingRequest() async throws { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test goes through all other event metrics other than opened push and makes sure that they don't get through the SDK when it's not initialized. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice. |
||
let expection = XCTestExpectation(description: "fatal error expected") | ||
environment.emitDeveloperWarning = { _ in | ||
// Would really runTimeWarn - not happening because we can't do that in tests so we fake it. | ||
expection.fulfill() | ||
} | ||
let store = TestStore(initialState: .init(queue: []), reducer: KlaviyoReducer()) | ||
let event = Event(name: .OpenedPush) | ||
_ = await store.send(.enqueueEvent(event)) | ||
|
||
let nonOpenedPushEvents = Event.EventName.allCases.filter { $0 != .OpenedPush } | ||
|
||
for event in nonOpenedPushEvents { | ||
let event = Event(name: event) | ||
_ = await store.send(.enqueueEvent(event)) | ||
} | ||
|
||
await fulfillment(of: [expection]) | ||
} | ||
|
||
|
@@ -423,3 +438,9 @@ class StateManagementEdgeCaseTests: XCTestCase { | |
} | ||
} | ||
} | ||
|
||
extension Event.EventName: CaseIterable { | ||
public static var allCases: [KlaviyoSwift.Event.EventName] { | ||
[.OpenedPush, .OpenedAppMetric, .ViewedProductMetric, .AddedToCartMetric, .StartedCheckoutMetric, .CustomEvent("someEvent")] | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just updated some test names to indicate the outcome we expect