refactor: normalize company size

This commit is contained in:
Shivam Mishra
2024-02-29 16:43:10 +05:30
parent 18188ae623
commit 4f43446237
6 changed files with 24 additions and 50 deletions
@@ -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
);
};
@@ -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);
});
});
@@ -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),
@@ -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
@@ -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',
+1 -1
View File
@@ -20,7 +20,7 @@ FactoryBot.define do
'industry' => 'Software'
},
'metrics' => {
'employees' => '1-10'
'employeesRange' => '10K-50K'
}
}
}.to_json