Skip to content

MOBILE-164: Forward raw 2xx sync-operation body to WebView JS#703

Merged
Vailence merged 3 commits into
developfrom
feature/MOBILE-164-Sync-send-error-raw
May 14, 2026
Merged

MOBILE-164: Forward raw 2xx sync-operation body to WebView JS#703
Vailence merged 3 commits into
developfrom
feature/MOBILE-164-Sync-send-error-raw

Conversation

@Vailence
Copy link
Copy Markdown
Collaborator

Ticket: https://tracker.yandex.ru/MOBILE-164

Summary

For WebView in-app syncOperation, HTTP 200 with body {"status":"ValidationError",...} was being flipped to Result.failure(.validationError(...)) by the network layer's BaseResponse parser, so the JS bridge sent a .error and JS landed in onError instead of onValidationError. Now any HTTP 2xx body is forwarded verbatim to JS as .response, matching Android — the JS Tracker dispatches on the body's status field. 4xx, 5xx and network errors keep the existing MindboxError → .error path.

Type of Change

  • Bug fix
  • Tests

Changes

  • NetworkFetcher / MBNetworkFetcher: new requestRaw(route:completion:) that reuses the existing pipeline with needBaseResponse: false and returns raw Data on HTTP 2xx.
  • EventRepository / MBEventRepository: new sendRaw(event:completion:) mirroring send<T> (config + deviceUUID guards, EventWrapper, makeRoute), hops back to main queue.
  • TransparentView.handleSyncOperation: now calls sendRaw; success → BridgeMessage(type: .response, payload: .string(rawBodyUTF8)); non-UTF-8 → error fallback; failure → unchanged MindboxError.createJSON() payload.
  • Pure helper TransparentView.makeSyncOperationResponse(result:action:id:) extracted so the JS-bridge contract is unit-testable without WKWebView.
  • Mocks (MockNetworkFetcher, MockFailureNetworkFetcher, EventRepositoryMock) extended for protocol conformance.

Untouched: public Mindbox.executeSyncOperation SDK API (still typed OperationResponse with BaseResponse parsing), guaranteed delivery, SDK logs, geo service.

Testing

  • Unit tests added/updated
  • Manual testing performed

Unit tests (Swift Testing + XCTest, 21 new tests, all green):

  • MBNetworkFetcherResponseHandlingTests — 7 new tests covering requestRaw for HTTP 200 (Success, ValidationError, arbitrary JSON, non-JSON), 403, 500, and missing configuration.
  • MBEventRepositorySendRawTests — success / failure pass-through, missing configuration, missing deviceUUID, main-queue hop, sync-event routing.
  • TransparentViewSyncOperationResponseTests — outgoing BridgeMessage for ValidationError body, 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:

  • pop-up 75310, button Sync - validation#content shows
    onValidationError - called[{"message":"Адрес электронной почты не является корректным.","location":"/customer/email"}]
  • success sync still hits onSuccess; HTTP 5xx still hits onError with MindboxError payload.

Vailence added 2 commits May 13, 2026 16:57
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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 raw Data on HTTP 2xx (skipping BaseResponse parsing).
  • Add EventRepository.sendRaw(event:completion:) + MBEventRepository.sendRaw(...) to send events and return raw 2xx bodies.
  • Update WebView TransparentView.handleSyncOperation to use sendRaw, and extract makeSyncOperationResponse for 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.

Comment thread Mindbox/Network/MBNetworkFetcher.swift Outdated
Comment thread Mindbox/InAppMessages/Presentation/Views/WebView/TransparentView.swift Outdated
@@ -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 */; };
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А чего в этом файле так много изменений вдруг?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Видимо что то поправилось автоматически, но по факту изменений тут только 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".
@Vailence Vailence merged commit 6e5bde5 into develop May 14, 2026
4 checks passed
@Vailence Vailence deleted the feature/MOBILE-164-Sync-send-error-raw branch May 14, 2026 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants