r/reactnative • u/WallabyWinter4027 • 15d ago
How are you testing the gap between your API and your app??
We renamed a field in a Go response structure last week, JSON tag stayed the same so every test on our side passed but the app was reading an old field from a cached response and showing users stale data for 3 days, both sides looked fine in isolation though and neither side owned the test that would’ve caught it.
Our backend is Go with chi and sqlc and postgres and the testing there is solid, httptest for handlers, testcontainers for DB, stripe mock for webhooks. Our detox tests mock the API so they wouldn’t have caught it either and nobody is testing for when a real user signs up in the app and the API creates the account and the webhook fires and the app shows the right state.
is this always the backend team’s problem? and if you do run full flows does that reside in the same CI or separate ?? because our test suite takes too long
1
u/deepyawn 15d ago
e2e tests on a git hook for finalized things runs on the Dev's machines and don't write test cases untill the things are completed and tested and finalized by manual QA tester and still make it ready to ship. And once things are completed on dev(internal test release) branch we take 7-10 days to baseline performance stats and bottlenecks while we review review each and everyline and then write the e2e cases(we don't run all the test cases we have a selected few files which we run and then we decide if this test cases always need to run with git hook or we when we explicily want to do a full 100% test of the application. If things are working fine under load and all things pass. We do the release. Our whole e2e suite takes 1h12m to 1h52m depending on the dev's machine but we do have 96% coverage. Honestly we just run it once week and it's overkill for us but in this age of ai I'm just happy that I can let juniors take over and I just do pr check and once in a while when I am lazy and run the suite so visual watch everything happens while I eat something.
1
u/DistributionDull1347 15d ago
I'd treat that boundary as shared ownership: pin the response contract (OpenAPI/Pact or a checked-in response fixture) and have the RN app test its real decoder/cache path against it, including a stale cached payload followed by refresh. Then keep one signup-to-webhook-to-fetch-state smoke flow in CI, while the broad Detox suite can run nightly or before release. That catches app/API drift without making every PR wait for the whole suite.
1
u/anthony-ball 15d ago
The stale cache part is what I'd fix first, because no test suite was going to catch that reliably. I parse every response through a zod schema in the API client layer and put a version in the cache key, so when the shape changes the old cached data gets thrown away instead of rendered. Parse failures also get reported as errors in production, which tells you within an hour that the backend changed something instead of days later. On ownership, whoever changes the response shape owns updating the shared schema, and backend CI checks real responses against it so the break shows up on their PR.
1
u/kenlawlpt 15d ago
Stale cache is a bit of an edge case. I just solved an issue like this which was reported a year ago, and I had no idea why users were being served the stale cache (until I asked AI and it found it in minutes).
You just learn to force fetch/refresh the cache when certain things happen, or based on whatever your app logic is.
1
u/NoBullfrog11 14d ago
we hit this seam in an expo app too, detox tests with a mocked api gave us confidence in screens but not in signup and profile creation actually lining up. the most useful middle ground was one short smoke flow against a staging backend after deploy, create a test account, assert the returned profile shape and key state, then clean it up. it caught integration drift without making every commit wait on a full device suite, and keeping teh fixture versioned made failures easier to pin down.
1
u/syedaalishan 13d ago
On your fixtures-vs-Pact question, I'd start with a few checked-in JSON responses and test them through the app's actual decoder and cache code. Don't automatically regenerate those fixtures whenever the backend changes, or both sides can agree on the same mistake. Include an old cached payload followed by a fresh response. Pact becomes more useful when independently released consumers need to state different compatibility requirements.
1
u/HeroSMS 11d ago
+1 to the shared fixture. One thing on the 3 days: if the cache is persisted (React Query persister, redux-persist, AsyncStorage), old entries need busting, not just the server fix.
Also check maxAge on whatever you persist. React Query's default is 24h, so 3 days would point to a longer setting or another cache layer.
Agree with keeping one smoke flow per PR and the rest nightly. Simple ownership rule on top, since you asked whose problem it is: whoever changes the contract updates the fixture in the same PR, and backend CI fails if they don't.