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);
});
});