Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/actions/submit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 23 additions & 0 deletions test/submit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Loading