From 33ba5f7fff59b73b0c2798e3ee228751314a6d21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matu=CC=81s=CC=8C=20Tomlein?= Date: Mon, 11 Nov 2024 15:41:55 +0100 Subject: [PATCH] Fix customPostPath configuration being ignored (close #1376) --- .../issue-fix_post_path_2024-11-11-14-42.json | 10 ++++++++++ libraries/tracker-core/src/emitter/index.ts | 2 ++ .../tracker-core/test/emitter/index.test.ts | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 common/changes/@snowplow/tracker-core/issue-fix_post_path_2024-11-11-14-42.json diff --git a/common/changes/@snowplow/tracker-core/issue-fix_post_path_2024-11-11-14-42.json b/common/changes/@snowplow/tracker-core/issue-fix_post_path_2024-11-11-14-42.json new file mode 100644 index 000000000..d998d58f4 --- /dev/null +++ b/common/changes/@snowplow/tracker-core/issue-fix_post_path_2024-11-11-14-42.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@snowplow/tracker-core", + "comment": "Fix customPostPath configuration being ignored (close #1376)", + "type": "none" + } + ], + "packageName": "@snowplow/tracker-core" +} \ No newline at end of file diff --git a/libraries/tracker-core/src/emitter/index.ts b/libraries/tracker-core/src/emitter/index.ts index ca142b7cf..0b7bfc783 100644 --- a/libraries/tracker-core/src/emitter/index.ts +++ b/libraries/tracker-core/src/emitter/index.ts @@ -198,6 +198,7 @@ interface RequestResult { export function newEmitter({ endpoint, eventMethod = 'post', + postPath, protocol, port, maxPostBytes = 40000, @@ -320,6 +321,7 @@ export function newEmitter({ maxPostBytes, useStm, credentials, + postPath, }); } diff --git a/libraries/tracker-core/test/emitter/index.test.ts b/libraries/tracker-core/test/emitter/index.test.ts index 6e01b131a..22c10ee23 100644 --- a/libraries/tracker-core/test/emitter/index.test.ts +++ b/libraries/tracker-core/test/emitter/index.test.ts @@ -333,3 +333,21 @@ test('adds a timeout to the request', async (t) => { t.is(requests.length, 1); t.is(await eventStore.count(), 1); }); + +test('uses custom POST path configured in the emitter', async (t) => { + const requests: Request[] = []; + const mockFetch = createMockFetch(200, requests); + const eventStore = newInMemoryEventStore({}); + const emitter: Emitter = newEmitter({ + endpoint: 'https://example.com', + customFetch: mockFetch, + postPath: '/custom', + eventStore, + }); + + await emitter.input({ e: 'pv' }); + await emitter.flush(); + + t.is(requests.length, 1); + t.is(requests[0].url, 'https://example.com/custom'); +});