Skip to content

Commit 1aabb0b

Browse files
landomencursoragent
authored andcommitted
PIR: Add unit tests for JS event handlers (#7334)
Task/Issue URL: https://app.asana.com/1/137249556945/project/1203581873609357/task/1212381653445208?focus=true ### Description Adds missing unit tests for the JS event handlers. ### Steps to test this PR Ensure the unit tests pass ### UI changes No UI changes <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds extensive unit tests covering PIR JS event handlers (state transitions, side effects, pixels, retries) and fixes a handler class name; also simplifies retry decision logic. > > - **Tests (new, extensive)**: > - `BrokerActionFailedEventHandlerTest`: verifies retry limits, expectation-only retries for scans, failure pixel emission. > - `BrokerStepCompletedEventHandlerTest`: validates success/failure outcomes, email confirmation flow, stage timing, and state resets. > - `CaptchaInfoReceivedEventHandlerTest`: asserts transaction ID handling, next-action progression, and pixel emission for opt-out. > - `EmailReceivedEventHandlerTest`: ensures email propagation to `ExtractedProfile`, generated email state, pixel emission, and next action. > - `ErrorReceivedHandlerTest`: maps various errors to `BrokerActionFailed` with no retry; state remains unchanged. > - `ExecuteBrokerStepActionEventHandlerTest`: covers side effects (`PushJsAction`, `LoadUrl`, captcha/email flows), delays, pixels, and data sourcing. > - `ExecuteNextBrokerStepEventHandlerTest`: starts next broker step, emits start pixels, resets indices, completes execution when done. > - `LoadUrlCompleteEventHandlerTest` / `LoadUrlFailedEventHandlerTest`: handle initial/recovery URLs, advance/abort flows, and retries. > - `RetryAwaitCaptchaSolutionEventHandlerTest` / `RetryGetCaptchaSolutionEventHandlerTest`: increment attempts and re-dispatch side effects. > - `StartedEventHandlerTest`: initializes attempt ID and kicks off initial URL load. > - **Minor fixes**: > - Rename `CaptchaInforReceivedEventHandler` to `CaptchaInfoReceivedEventHandler`. > - Simplify `shouldRetryFailedAction` with an expression `return` while preserving behavior. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 55bc3fd. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 64d8c5b commit 1aabb0b

14 files changed

+4138
-4
lines changed

pir/pir-impl/src/main/java/com/duckduckgo/pir/impl/common/actions/BrokerActionFailedEventHandler.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ class BrokerActionFailedEventHandler @Inject constructor(
101101
return false
102102
}
103103

104-
if (state.runType == RunType.OPTOUT || state.runType == RunType.EMAIL_CONFIRMATION) {
104+
return if (state.runType == RunType.OPTOUT || state.runType == RunType.EMAIL_CONFIRMATION) {
105105
// for optout, for ANY action we retry at most 3 times
106-
return state.actionRetryCount < MAX_RETRY_COUNT_OPTOUT
106+
state.actionRetryCount < MAX_RETRY_COUNT_OPTOUT
107107
} else {
108108
// For scans, we ONLY retry once if the action is expectation
109-
return (currentAction is Expectation && state.actionRetryCount < MAX_RETRY_COUNT_SCAN)
109+
(currentAction is Expectation && state.actionRetryCount < MAX_RETRY_COUNT_SCAN)
110110
}
111111
}
112112

pir/pir-impl/src/main/java/com/duckduckgo/pir/impl/common/actions/CaptchaInforReceivedEventHandler.kt renamed to pir/pir-impl/src/main/java/com/duckduckgo/pir/impl/common/actions/CaptchaInfoReceivedEventHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import kotlin.reflect.KClass
3535
scope = AppScope::class,
3636
boundType = EventHandler::class,
3737
)
38-
class CaptchaInforReceivedEventHandler @Inject constructor(
38+
class CaptchaInfoReceivedEventHandler @Inject constructor(
3939
private val currentTimeProvider: CurrentTimeProvider,
4040
private val pirRunStateHandler: PirRunStateHandler,
4141
) : EventHandler {

0 commit comments

Comments
 (0)