From 5a68ca82538e953f870cac2319cefab9aac1a208 Mon Sep 17 00:00:00 2001 From: Philip Jackson Date: Wed, 19 Jun 2019 17:32:31 +1200 Subject: [PATCH] Signup: Remove invalid site_type parameter from verticals request (#33918) Remove invalid site_type parameter from verticals request Some flows do not choose a site type before requesting verticals from the API (e.g. 'desktop'). If the site type hasn't been choosen then don't send the site_type parameter as part of the request. The server can then choose what the default site type should be. --- client/state/data-layer/wpcom/signup/verticals/index.js | 4 +++- .../data-layer/wpcom/signup/verticals/test/index.js | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/client/state/data-layer/wpcom/signup/verticals/index.js b/client/state/data-layer/wpcom/signup/verticals/index.js index c451df3bffa18..56e91345365f8 100644 --- a/client/state/data-layer/wpcom/signup/verticals/index.js +++ b/client/state/data-layer/wpcom/signup/verticals/index.js @@ -18,6 +18,8 @@ import { setVerticals } from 'state/signup/verticals/actions'; import { SIGNUP_VERTICALS_REQUEST } from 'state/action-types'; import { getSiteTypeId } from 'state/signup/steps/site-type/selectors'; +// Some flows do not choose a site type before requesting verticals. In this +// case don't send a site_type param to the API. export const requestVerticals = action => http( { @@ -26,7 +28,7 @@ export const requestVerticals = action => path: '/verticals', query: { search: action.search.trim(), - site_type: action.siteTypeId, + ...( action.siteTypeId && { site_type: action.siteTypeId } ), limit: action.limit, include_preview: true, }, diff --git a/client/state/data-layer/wpcom/signup/verticals/test/index.js b/client/state/data-layer/wpcom/signup/verticals/test/index.js index 9b1dbd71d3816..2d52428559b13 100644 --- a/client/state/data-layer/wpcom/signup/verticals/test/index.js +++ b/client/state/data-layer/wpcom/signup/verticals/test/index.js @@ -34,6 +34,15 @@ describe( 'data-layer/wpcom/signup/verticals', () => { ); } ); + test( 'requestVerticals() with missing siteTypeId', () => { + const mockAction = { + search: 'Foo', + limit: 7, + }; + + expect( requestVerticals( mockAction ) ).not.toHaveProperty( 'query.site_type' ); + } ); + test( 'storeVerticals()', () => { const search = 'Profit!'; const siteType = 'business';