MOBILE-164: Forward raw 2xx sync-operation body to WebView JS#703
Conversation
Cover MBNetworkFetcher.requestRaw, MBEventRepository.sendRaw, and the WebView sync-operation response shaping. Extract a pure helper TransparentView.makeSyncOperationResponse so the JS-bridge contract is unit-testable without spinning up WKWebView.
There was a problem hiding this comment.
Pull request overview
This PR updates the WebView syncOperation flow to forward raw HTTP 2xx response bodies to JS (instead of forcing BaseResponse parsing), so the JS Tracker can dispatch on the body’s status field (e.g. ValidationError stays on the “success/response” path). It introduces requestRaw/sendRaw plumbing, updates TransparentView to use it, and adds unit tests covering the new behavior.
Changes:
- Add
NetworkFetcher.requestRaw(route:completion:)+MBNetworkFetcher.requestRaw(...)to return rawDataon HTTP 2xx (skippingBaseResponseparsing). - Add
EventRepository.sendRaw(event:completion:)+MBEventRepository.sendRaw(...)to send events and return raw 2xx bodies. - Update WebView
TransparentView.handleSyncOperationto usesendRaw, and extractmakeSyncOperationResponsefor unit-testable JS-bridge contract; add new tests and update mocks/project.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| MindboxTests/Network/MBNetworkFetcherResponseHandlingTests.swift | Adds coverage for requestRaw result mapping (2xx raw success, 4xx/5xx errors, missing config). |
| MindboxTests/Network/MBEventRepositorySendRawTests.swift | New tests for MBEventRepository.sendRaw routing, config/UUID guards, and main-queue delivery. |
| MindboxTests/Mock/MockNetworkFetcher.swift | Updates mock to conform to new requestRaw requirement. |
| MindboxTests/Mock/MockFailureNetworkFetcher.swift | Updates failure mock to conform to new requestRaw requirement. |
| MindboxTests/MindboxLogger/Mocks/EventRepositoryMock.swift | Updates repository mock to conform to new sendRaw requirement. |
| MindboxTests/InApp/Tests/TransparentViewSyncOperationResponseTests.swift | New tests validating makeSyncOperationResponse output contract (success, non-UTF8 fallback, errors). |
| Mindbox/NetworkRepository/Event/MBEventRepository.swift | Implements sendRaw that uses fetcher.requestRaw and delivers completion on main queue for network results. |
| Mindbox/NetworkRepository/Event/EventRepository.swift | Extends repository protocol with sendRaw + documentation. |
| Mindbox/Network/MBNetworkFetcher.swift | Implements requestRaw reusing shared response pipeline with needBaseResponse: false. |
| Mindbox/Network/Abstract/NetworkFetcher.swift | Extends fetcher protocol with requestRaw + documentation. |
| Mindbox/InAppMessages/Presentation/Views/WebView/TransparentView.swift | Routes syncOperation through raw forwarding, adds makeSyncOperationResponse helper. |
| Mindbox.xcodeproj/project.pbxproj | Registers new test sources and reflects Xcode project structure adjustments. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -11,13 +11,11 @@ | |||
| 0E7A224A082FA2DA35706CC7 /* MotionServiceResolvePositionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C8192B8B7043EF74D05B36B /* MotionServiceResolvePositionTests.swift */; }; | |||
| 0E7A224A082FA2DA35706CC8 /* MotionServiceShakeToEditTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C8192B8B7043EF74D05B36C /* MotionServiceShakeToEditTests.swift */; }; | |||
| 1E3BD63AB3F1521C253CB818 /* MBNetworkFetcherResponseHandlingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97FEDDEB5F71A67F1C4C675F /* MBNetworkFetcherResponseHandlingTests.swift */; }; | |||
There was a problem hiding this comment.
А чего в этом файле так много изменений вдруг?
There was a problem hiding this comment.
Видимо что то поправилось автоматически, но по факту изменений тут только 2
- MBNetworkFetcher.requestRaw: capture self strongly so completion is always invoked even if the fetcher were deallocated mid-request (matches the existing `request<T>` pattern). - TransparentView.handleSyncOperation: build the outgoing BridgeMessage first, then log based on its `type` so the non-UTF-8 fallback path reports "failed" instead of "success".
Ticket: https://tracker.yandex.ru/MOBILE-164
Summary
For WebView in-app
syncOperation, HTTP 200 with body{"status":"ValidationError",...}was being flipped toResult.failure(.validationError(...))by the network layer'sBaseResponseparser, so the JS bridge sent a.errorand JS landed inonErrorinstead ofonValidationError. Now any HTTP 2xx body is forwarded verbatim to JS as.response, matching Android — the JS Tracker dispatches on the body'sstatusfield. 4xx, 5xx and network errors keep the existingMindboxError → .errorpath.Type of Change
Changes
NetworkFetcher/MBNetworkFetcher: newrequestRaw(route:completion:)that reuses the existing pipeline withneedBaseResponse: falseand returns rawDataon HTTP 2xx.EventRepository/MBEventRepository: newsendRaw(event:completion:)mirroringsend<T>(config +deviceUUIDguards,EventWrapper,makeRoute), hops back to main queue.TransparentView.handleSyncOperation: now callssendRaw; success →BridgeMessage(type: .response, payload: .string(rawBodyUTF8)); non-UTF-8 → error fallback; failure → unchangedMindboxError.createJSON()payload.TransparentView.makeSyncOperationResponse(result:action:id:)extracted so the JS-bridge contract is unit-testable withoutWKWebView.MockNetworkFetcher,MockFailureNetworkFetcher,EventRepositoryMock) extended for protocol conformance.Untouched: public
Mindbox.executeSyncOperationSDK API (still typedOperationResponsewithBaseResponseparsing), guaranteed delivery, SDK logs, geo service.Testing
Unit tests (Swift Testing + XCTest, 21 new tests, all green):
MBNetworkFetcherResponseHandlingTests— 7 new tests coveringrequestRawfor HTTP 200 (Success,ValidationError, arbitrary JSON, non-JSON), 403, 500, and missing configuration.MBEventRepositorySendRawTests— success / failure pass-through, missing configuration, missingdeviceUUID, main-queue hop, sync-event routing.TransparentViewSyncOperationResponseTests— outgoingBridgeMessageforValidationErrorbody, success body byte-equality, non-UTF-8 fallback, connection/protocol failures, action/id propagation.Full test target (963/963) passes.
Manual verification on test-staging:
#contentshowsonValidationError - called[{"message":"Адрес электронной почты не является корректным.","location":"/customer/email"}]onSuccess; HTTP 5xx still hitsonErrorwithMindboxErrorpayload.