teqo-backup/tests/unit/homeSearchMunicipalityMatch.unit.spec.ts
Francisco Ignácio Fontoura Solla 0e73d47a62 B50: home search Assessores group for unrestricted staff.
Word-start on name, municipality count on the row, shared HomeSearchHitRow; POST /campanha/home-search aggregates advisors alongside municipalities.
2026-07-29 22:09:42 -03:00

24 lines
923 B
TypeScript

import { describe, expect, it } from 'vitest'
import {
compareHomeSearchNameRelevance,
homeSearchNameRelevanceTier,
} from '@/lib/homeSearchMunicipalityMatch'
describe('homeSearchMunicipalityMatch', () => {
it('ranks prefix match before word-start later in the label', () => {
expect(homeSearchNameRelevanceTier('cairu', 'cai')).toBe(0)
expect(homeSearchNameRelevanceTier('porto seguro', 'seg')).toBe(1)
})
it('sorts by relevance tier then tie-break desc', () => {
const normalizedQuery = 'cai'
const hits = [
{ normalizedName: 'porto seguro', tieBreakDesc: 9000 },
{ normalizedName: 'cairu', tieBreakDesc: 100 },
{ normalizedName: 'caicara', tieBreakDesc: 5000 },
]
const sorted = [...hits].sort((a, b) => compareHomeSearchNameRelevance(a, b, normalizedQuery))
expect(sorted.map((row) => row.normalizedName)).toEqual(['caicara', 'cairu', 'porto seguro'])
})
})