From 4f43446237009fd945d248dab9bab66f4bb2d5b5 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Thu, 29 Feb 2024 16:40:52 +0530 Subject: [PATCH] refactor: normalize company size --- app/javascript/v3/helpers/OnboardingHelper.js | 11 -------- .../v3/helpers/specs/OnboardingHelper.spec.js | 27 +------------------ .../v3/views/onboarding/SetupCompany.vue | 14 +++------- .../enterprise/clearbit_lookup_service.rb | 18 ++++++++++++- .../clearbit_lookup_service_spec.rb | 2 +- spec/factories/clearbit_response.rb | 2 +- 6 files changed, 24 insertions(+), 50 deletions(-) diff --git a/app/javascript/v3/helpers/OnboardingHelper.js b/app/javascript/v3/helpers/OnboardingHelper.js index b82ec6d79..6192cbea1 100644 --- a/app/javascript/v3/helpers/OnboardingHelper.js +++ b/app/javascript/v3/helpers/OnboardingHelper.js @@ -4,14 +4,3 @@ export const findMatchingOption = (value, options, defaultValue) => { ); return match ? match.value || match : defaultValue; }; - -export const findCompanySizeMatch = (options, size) => { - if (!size) return undefined; - if (Number.isNaN(size)) return undefined; - return ( - options.find(option => { - const upperLimit = option.value.split('-')[1]?.split('+')[0]; - return size < (upperLimit ? Number(upperLimit) : Infinity); - })?.value || options[0].value - ); -}; diff --git a/app/javascript/v3/helpers/specs/OnboardingHelper.spec.js b/app/javascript/v3/helpers/specs/OnboardingHelper.spec.js index f75e92fad..7467d3227 100644 --- a/app/javascript/v3/helpers/specs/OnboardingHelper.spec.js +++ b/app/javascript/v3/helpers/specs/OnboardingHelper.spec.js @@ -1,4 +1,4 @@ -import { findMatchingOption, findCompanySizeMatch } from '../OnboardingHelper'; +import { findMatchingOption } from '../OnboardingHelper'; describe('findMatchingOption', () => { const options = [{ value: 'option1' }, { value: 'option2' }]; @@ -13,28 +13,3 @@ describe('findMatchingOption', () => { ); }); }); - -describe('findCompanySizeMatch', () => { - const mockCompanySizeOptions = [ - { value: '1-10' }, - { value: '11-50' }, - { value: '51-500' }, - { value: '501-1000' }, - { value: '1001+' }, - ]; - - it('should return the correct company size range', () => { - const size = 25; - expect(findCompanySizeMatch(mockCompanySizeOptions, size)).toBe('11-50'); - }); - - it('should return the last company size range when limit exceeds', () => { - const size = 1500; - expect(findCompanySizeMatch(mockCompanySizeOptions, size)).toBe('1001+'); - }); - - it('should return the undefined when no match is found', () => { - const size = undefined; - expect(findCompanySizeMatch(mockCompanySizeOptions, size)).toBe(undefined); - }); -}); diff --git a/app/javascript/v3/views/onboarding/SetupCompany.vue b/app/javascript/v3/views/onboarding/SetupCompany.vue index 12f6644ad..1d940eb90 100644 --- a/app/javascript/v3/views/onboarding/SetupCompany.vue +++ b/app/javascript/v3/views/onboarding/SetupCompany.vue @@ -94,10 +94,7 @@ import { ONBOARDING_STEP_NAMES } from 'dashboard/constants/globals'; import SubmitButton from 'dashboard/components/buttons/FormSubmitButton.vue'; import { timeZoneOptions } from 'dashboard/routes/dashboard/settings/inbox/helpers/businessHour.js'; import { getBrowserTimezone, getBrowserLocale } from 'v3/helpers/BrowserHelper'; -import { - findMatchingOption, - findCompanySizeMatch, -} from 'v3/helpers/OnboardingHelper'; +import { findMatchingOption } from 'v3/helpers/OnboardingHelper'; import alertMixin from 'shared/mixins/alertMixin'; import configMixin from 'shared/mixins/configMixin'; export default { @@ -118,8 +115,8 @@ export default { companySizeOptions: [ { value: '1-10', label: '1-10' }, { value: '11-50', label: '11-50' }, - { value: '51-500', label: '51-500' }, - { value: '501-1000', label: '501-1000' }, + { value: '51-250', label: '51-250' }, + { value: '251-1000', label: '251-1000' }, { value: '1001+', label: 'Over 1000' }, ], industryOptions: [ @@ -235,10 +232,7 @@ export default { this.industryOptions, 'other' ); - this.companySize = findCompanySizeMatch( - this.companySizeOptions, - companySize - ); + this.companySize = companySize; this.timezone = findMatchingOption( timezone, this.timeZones.map(zone => zone.value), diff --git a/enterprise/app/services/enterprise/clearbit_lookup_service.rb b/enterprise/app/services/enterprise/clearbit_lookup_service.rb index c108ca153..689830cab 100644 --- a/enterprise/app/services/enterprise/clearbit_lookup_service.rb +++ b/enterprise/app/services/enterprise/clearbit_lookup_service.rb @@ -86,7 +86,23 @@ class Enterprise::ClearbitLookupService timezone: data.dig('company', 'timeZone'), logo: data.dig('company', 'logo'), industry: data.dig('company', 'category', 'industry'), - company_size: data.dig('company', 'metrics', 'employees') + company_size: normalize_company_size(data.dig('company', 'metrics', 'employeesRange')) } end + + def self.normalize_company_size(size) + sizemap = { + '1-10' => '1-10', + '11-50' => '11-50', + '51-250' => '51-250', + '251-1K' => '250-1000', + '1K-5K' => '1001+', + '5K-10K' => '1001+', + '10K-50K' => '1001+', + '50K-100K' => '1001+', + '100K+' => '1001+' + } + + sizemap[size] || nil + end end diff --git a/spec/enterprise/services/enterprise/clearbit_lookup_service_spec.rb b/spec/enterprise/services/enterprise/clearbit_lookup_service_spec.rb index 725aa6523..13f80949f 100644 --- a/spec/enterprise/services/enterprise/clearbit_lookup_service_spec.rb +++ b/spec/enterprise/services/enterprise/clearbit_lookup_service_spec.rb @@ -22,7 +22,7 @@ RSpec.describe Enterprise::ClearbitLookupService do expect(result).to eq({ :avatar => 'https://example.com/avatar.png', :company_name => 'Doe Inc.', - :company_size => '1-10', + :company_size => '1001+', :industry => 'Software', :logo => nil, :name => 'John Doe', diff --git a/spec/factories/clearbit_response.rb b/spec/factories/clearbit_response.rb index fbe8e9a5a..0b4f3356a 100644 --- a/spec/factories/clearbit_response.rb +++ b/spec/factories/clearbit_response.rb @@ -20,7 +20,7 @@ FactoryBot.define do 'industry' => 'Software' }, 'metrics' => { - 'employees' => '1-10' + 'employeesRange' => '10K-50K' } } }.to_json