Skip to content

Commit

Permalink
Fixing unit tests for Subscribe Effects and DelayedHeartbeatEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
jguz-pubnub committed Feb 22, 2024
1 parent d5c5083 commit 2f04aaf
Show file tree
Hide file tree
Showing 2 changed files with 313 additions and 248 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ class DelayedHeartbeatEffectTests: XCTestCase {
}

override func tearDown() {
mockUrlSession = nil
delegate = nil
mockUrlSession = nil
httpSession = nil
factory = nil
super.tearDown()
}

Expand All @@ -43,7 +44,7 @@ class DelayedHeartbeatEffectTests: XCTestCase {

let delayRange = 2.0...3.0
let automaticRetry = AutomaticRetry(retryLimit: 3, policy: .linear(delay: delayRange.lowerBound), excluded: [])
let effect = configureEffect(attempt: 0, automaticRetry: automaticRetry, error: PubNubError(.unknown))
let effect = configureEffectToTest(retryAttempt: 0, automaticRetry: automaticRetry, dueTo: PubNubError(.unknown))
let startDate = Date()

effect.performTask { returnedEvents in
Expand All @@ -65,7 +66,7 @@ class DelayedHeartbeatEffectTests: XCTestCase {
let delayRange = 2.0...3.0
let automaticRetry = AutomaticRetry(retryLimit: 3, policy: .linear(delay: delayRange.lowerBound), excluded: [])
let error = PubNubError(.unknown)
let effect = configureEffect(attempt: 0, automaticRetry: automaticRetry, error: error)
let effect = configureEffectToTest(retryAttempt: 0, automaticRetry: automaticRetry, dueTo: error)

effect.performTask { returnedEvents in
let expectedError = PubNubError(.internalServiceError)
Expand All @@ -84,7 +85,7 @@ class DelayedHeartbeatEffectTests: XCTestCase {

let automaticRetry = AutomaticRetry(retryLimit: 3, policy: .linear(delay: 2.0), excluded: [])
let error = PubNubError(.unknown)
let effect = configureEffect(attempt: 3, automaticRetry: automaticRetry, error: error)
let effect = configureEffectToTest(retryAttempt: 3, automaticRetry: automaticRetry, dueTo: error)

mockResponse(GenericServicePayloadResponse(status: 200))

Expand All @@ -108,9 +109,10 @@ fileprivate extension DelayedHeartbeatEffectTests {
}
}

func configureEffect(
attempt: Int, automaticRetry: AutomaticRetry?,
error: PubNubError
func configureEffectToTest(
retryAttempt attempt: Int,
automaticRetry: AutomaticRetry?,
dueTo error: PubNubError
) -> any EffectHandler<Presence.Event> {
factory.effect(
for: .delayedHeartbeat(
Expand Down
Loading

0 comments on commit 2f04aaf

Please sign in to comment.