From 32bb3c4bf3d04b872772ddbc17cf304544dfadcc Mon Sep 17 00:00:00 2001 From: dylandepass Date: Thu, 16 Jul 2026 11:07:55 -0400 Subject: [PATCH] fix(submit): pass through client-provided leadSource to EBS The newsletter payload was hardcoding LeadSource to 'edge-commerce', ignoring any value sent by the client. Now uses data.leadSource when it is a non-empty string, falling back to 'edge-commerce' otherwise. --- src/actions/submit/index.js | 2 +- test/submit.test.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/actions/submit/index.js b/src/actions/submit/index.js index 1068c7a..dfeaec4 100644 --- a/src/actions/submit/index.js +++ b/src/actions/submit/index.js @@ -268,7 +268,7 @@ async function callNewsletterApi(ctx, formId, data) { FirstName: '', MiddleName: '', LastName: '', - LeadSource: 'edge-commerce', + LeadSource: (data.leadSource && typeof data.leadSource === 'string') ? data.leadSource : 'edge-commerce', Country: 'US', Company: 'HOUSEHOLD', EmailAddress: data.email, diff --git a/test/submit.test.js b/test/submit.test.js index 104fa9b..ab3f0a7 100644 --- a/test/submit.test.js +++ b/test/submit.test.js @@ -906,6 +906,29 @@ describe('submit action', () => { expect(body.EmailAddress).toBe('test@example.com'); expect(body.EmailOptIn).toBe(true); expect(body.workFlowName).toBe('subscription'); + expect(body.LeadSource).toBe('edge-commerce'); + }); + + test('uses client-provided leadSource when present', async () => { + mockMakeContext.mockResolvedValue(makeNewsletterCtx({ leadSource: 'vitamix-promo' })); + mockProxyFetch.mockResolvedValue({ status: 200, json: jest.fn().mockResolvedValue({}) }); + + await main({}); + + const [, , opts] = mockProxyFetch.mock.calls[0]; + const body = JSON.parse(opts.body); + expect(body.LeadSource).toBe('vitamix-promo'); + }); + + test('falls back to edge-commerce when leadSource is not a string', async () => { + mockMakeContext.mockResolvedValue(makeNewsletterCtx({ leadSource: 123 })); + mockProxyFetch.mockResolvedValue({ status: 200, json: jest.fn().mockResolvedValue({}) }); + + await main({}); + + const [, , opts] = mockProxyFetch.mock.calls[0]; + const body = JSON.parse(opts.body); + expect(body.LeadSource).toBe('edge-commerce'); }); test('returns proxied response body and status', async () => {