@@ -116,7 +116,7 @@ class StateManagementEdgeCaseTests: XCTestCase {
116
116
// MARK: - Set Email
117
117
118
118
@MainActor
119
- func testSetEmailUninitialized ( ) async throws {
119
+ func testSetEmailUninitializedDoesNotAddToPendingRequest ( ) async throws {
120
120
let expection = XCTestExpectation ( description: " fatal error expected " )
121
121
environment. emitDeveloperWarning = { _ in
122
122
// Would really fatalError - not happening because we can't do that in tests so we fake it.
@@ -168,7 +168,7 @@ class StateManagementEdgeCaseTests: XCTestCase {
168
168
// MARK: - Set External Id
169
169
170
170
@MainActor
171
- func testSetExternalIdUninitialized ( ) async throws {
171
+ func testSetExternalIdUninitializedDoesNotAddToPendingRequest ( ) async throws {
172
172
let apiKey = " fake-key "
173
173
let initialState = KlaviyoState ( apiKey: apiKey,
174
174
anonymousId: environment. analytics. uuid ( ) . uuidString,
@@ -213,7 +213,7 @@ class StateManagementEdgeCaseTests: XCTestCase {
213
213
// MARK: - Set Phone number
214
214
215
215
@MainActor
216
- func testSetPhoneNumberUninitialized ( ) async throws {
216
+ func testSetPhoneNumberUninitializedDoesNotAddToPendingRequest ( ) async throws {
217
217
let apiKey = " fake-key "
218
218
let initialState = KlaviyoState ( apiKey: apiKey,
219
219
anonymousId: environment. analytics. uuid ( ) . uuidString,
@@ -257,7 +257,7 @@ class StateManagementEdgeCaseTests: XCTestCase {
257
257
// MARK: - Set Push Token
258
258
259
259
@MainActor
260
- func testSetPushTokenUninitialized ( ) async throws {
260
+ func testSetPushTokenUninitializedDoesNotAddToPendingRequest ( ) async throws {
261
261
let apiKey = " fake-key "
262
262
let initialState = KlaviyoState ( apiKey: apiKey,
263
263
anonymousId: environment. analytics. uuid ( ) . uuidString,
@@ -369,15 +369,30 @@ class StateManagementEdgeCaseTests: XCTestCase {
369
369
// MARK: - set enqueue event uninitialized
370
370
371
371
@MainActor
372
- func testEnqueueEventUninitialized( ) async throws {
372
+ func testOpenedPushEventUninitializedAddsToPendingRequests( ) async throws {
373
+ let store = TestStore ( initialState: . init( queue: [ ] ) , reducer: KlaviyoReducer ( ) )
374
+ let event = Event ( name: . OpenedPush)
375
+ _ = await store. send ( . enqueueEvent( event) ) {
376
+ $0. pendingRequests = [ . event( event) ]
377
+ }
378
+ }
379
+
380
+ @MainActor
381
+ func testEnqueueNonOpenedPushEventUninitializedDoesNotAddToPendingRequest( ) async throws {
373
382
let expection = XCTestExpectation ( description: " fatal error expected " )
374
383
environment. emitDeveloperWarning = { _ in
375
384
// Would really runTimeWarn - not happening because we can't do that in tests so we fake it.
376
385
expection. fulfill ( )
377
386
}
378
387
let store = TestStore ( initialState: . init( queue: [ ] ) , reducer: KlaviyoReducer ( ) )
379
- let event = Event ( name: . OpenedPush)
380
- _ = await store. send ( . enqueueEvent( event) )
388
+
389
+ let nonOpenedPushEvents = Event . EventName. allCases. filter { $0 != . OpenedPush }
390
+
391
+ for event in nonOpenedPushEvents {
392
+ let event = Event ( name: event)
393
+ _ = await store. send ( . enqueueEvent( event) )
394
+ }
395
+
381
396
await fulfillment ( of: [ expection] )
382
397
}
383
398
@@ -423,3 +438,9 @@ class StateManagementEdgeCaseTests: XCTestCase {
423
438
}
424
439
}
425
440
}
441
+
442
+ extension Event . EventName : CaseIterable {
443
+ public static var allCases : [ KlaviyoSwift . Event . EventName ] {
444
+ [ . OpenedPush, . OpenedAppMetric, . ViewedProductMetric, . AddedToCartMetric, . StartedCheckoutMetric, . CustomEvent( " someEvent " ) ]
445
+ }
446
+ }
0 commit comments