Skip to content

Commit

Permalink
Refactored filterObjectEmptyValues utility
Browse files Browse the repository at this point in the history
  • Loading branch information
silversonicaxel committed Sep 6, 2024
1 parent adc768b commit 0c3b540
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/components/search-area/search-area.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { DialogLazy } from 'src/components/dialog'
import { useDialog } from 'src/components/dialog/hooks/useDialog'
import { useTranslationClient } from 'src/helpers/hooks/useTranslationClient'
import { isObjectNull } from 'src/helpers/utils/isObjectNull'
import { purgeObjectEmptyValues } from 'src/helpers/utils/purgeObjectEmptyValues'
import { filterObjectEmptyValues } from 'src/helpers/utils/filterObjectEmptyValues'
import { CountryCode } from 'src/types/country'
import { SearchPlacesFormInput } from 'src/types/search'

Expand Down Expand Up @@ -56,7 +56,7 @@ export const SearchArea: FC<SearchAreaProps> = ({ countries, totalPlaces }) => {
}
else {
const params = new URLSearchParams(searchParams)
params.set('query', JSON.stringify(purgeObjectEmptyValues(data)))
params.set('query', JSON.stringify(filterObjectEmptyValues(data)))
params.delete('page')

replace(`${pathname}?${params.toString()}`)
Expand Down
15 changes: 15 additions & 0 deletions src/helpers/utils/filterObjectEmptyValues.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { describe, expect, test } from 'vitest'

import { filterObjectEmptyValues } from './filterObjectEmptyValues'


describe('Helpers > Utils > filterObjectEmptyValues', () => {
test('return empty object', () => {
expect(filterObjectEmptyValues({})).toEqual({})
})

test('return object with keys associated to filled string', () => {
expect(filterObjectEmptyValues({ name: 'book', iso: null, city: '', website: undefined }))
.toEqual({ name: 'book' })
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { EmptyObject } from 'type-fest'
import { isObjectNull } from './isObjectNull'


export const purgeObjectEmptyValues = (
export const filterObjectEmptyValues = (
obj: Record<string, string | null | undefined> | EmptyObject
) => {
if (isObjectNull(obj)) {
Expand Down
15 changes: 0 additions & 15 deletions src/helpers/utils/purgeObjectEmptyFields.test.ts

This file was deleted.

0 comments on commit 0c3b540

Please sign in to comment.