Skip to content

Commit a4ea2c1

Browse files
Jiaming Youmeta-codesync[bot]
authored andcommitted
Real-builder all-fields integration tests
Summary: Bring Python, Java, and Ruby to parity with the NodeJS/PHP suites: exercise the REAL registry ParamBuilder (no mocks) for every default field these three ports auto-populate from the request context -- fbc, fbp, event_source_url, and referrer_url -- not just fbp. Previously these three suites covered the full auto-populate matrix with a MOCKED ParamBuilder and touched the real dependency only via an API-existence guardrail plus a single fbp case. This adds real-builder cases for the remaining fields (extraction + caller-precedence + Preference gating), so the SDK<->upstream contract is exercised end-to-end against the pinned registry versions. Also fixes a latent bug in the existing Python and Ruby real-builder tests: they passed a nested {headers:{cookie:...}} context, but the real RequestContextAdaptor reads flat env keys (HTTP_HOST / HTTP_COOKIE / ...). With no cookie seen, the builder GENERATES a fresh fbp and the weak startswith('fb.') assertion passed spuriously. Switched to the flat env shape and assert on the supplied cookie value. (Java's existing real test already used the correct flat shape.) The upstream builder appends an appendix token to every value, so assertions match the prefix (startsWith / start_with the input) rather than exact equality. Note: client_ip_address is intentionally not covered for these three ports -- none of them auto-populate it from the builder (only PHP/NodeJS do). Reviewed By: xuanjie22 Differential Revision: D107207093 fbshipit-source-id: ee5f074ae11515b7f8ad621896bea5a700bf2748
1 parent 7d16f93 commit a4ea2c1

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

src/test/java/com/facebook/ads/sdk/serverside/EventRequestContextTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,4 +450,51 @@ public void testSetRequestContextPopulatesFbpFromCookieEndToEnd() {
450450
assertTrue("fbp should start with the cookie value",
451451
ud.getFbp().startsWith("fb.1.1700000000000.987654321"));
452452
}
453+
454+
// Flat environ-style Map — the shape RequestContextAdaptor reads for raw Maps.
455+
// The upstream 1.3.0 ParamBuilder appends an appendix token to every value, so
456+
// assert on the prefix rather than exact equality.
457+
private static Map<String, Object> realCtx() {
458+
Map<String, Object> c = new HashMap<>();
459+
c.put("HTTP_HOST", "shop.example.com");
460+
c.put("HTTP_COOKIE",
461+
"_fbc=fb.1.1700000000000.AbCdEf12345; _fbp=fb.1.1700000000000.987654321");
462+
c.put("HTTP_REFERER", "https://google.com/search?q=foo");
463+
c.put("REQUEST_URI", "/cart");
464+
c.put("HTTPS", "on");
465+
return c;
466+
}
467+
468+
@Test
469+
public void testRealBuilderAutoPopulatesFbcFromCookie() {
470+
Event event = new Event().eventName("PageView").eventTime(1700000010L)
471+
.setRequestContext(realCtx());
472+
event.applyParamBuilderDefaults();
473+
String fbc = event.getUserData().getFbc();
474+
assertNotNull("fbc should be auto-populated from the _fbc cookie", fbc);
475+
assertTrue("fbc not extracted from cookie: " + fbc,
476+
fbc.startsWith("fb.1.1700000000000.AbCdEf12345"));
477+
}
478+
479+
@Test
480+
public void testRealBuilderAutoPopulatesEventSourceUrl() {
481+
Event event = new Event().eventName("PageView").eventTime(1700000060L)
482+
.setRequestContext(realCtx());
483+
event.applyParamBuilderDefaults();
484+
String esu = event.getEventSourceUrl();
485+
assertNotNull("event_source_url should be built from host + uri", esu);
486+
assertTrue("event_source_url unexpected: " + esu,
487+
esu.startsWith("https://shop.example.com/cart"));
488+
}
489+
490+
@Test
491+
public void testRealBuilderAutoPopulatesReferrerUrl() {
492+
Event event = new Event().eventName("PageView").eventTime(1700000070L)
493+
.setRequestContext(realCtx());
494+
event.applyParamBuilderDefaults();
495+
String ref = event.getReferrerUrl();
496+
assertNotNull("referrer_url should be extracted from the Referer header", ref);
497+
assertTrue("referrer_url unexpected: " + ref,
498+
ref.startsWith("https://google.com/search?q=foo"));
499+
}
453500
}

0 commit comments

Comments
 (0)