Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
jtmst committed May 20, 2024
1 parent 3cb1c20 commit f7be4ce
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/data/helpers/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { findClosestTopic } from './';

describe('findClosestTopic', () => {
const legalTopics = [
{
name: 'Housing',
codes: ['HO-01-00-00-00', 'HO-02-00-00-00'],
},
{
name: 'Family',
codes: ['FA-00-00-00-00', 'FA-01-00-00-00'],
},
{
name: 'Employment',
codes: ['EM-01-00-00-00'],
},
];

it('should return the exact matching topic', () => {
const topicCode = 'HO-02-00-00-00';
const result = findClosestTopic(topicCode, legalTopics);
expect(result.name).toBe('Housing');
});

it('should return the closest smaller match if exact match is not available', () => {
const topicCode = 'HO-01-50-00-00';
const result = findClosestTopic(topicCode, legalTopics);
expect(result.name).toBe('Housing');
});

it('should return undefined if no prefix matches', () => {
const topicCode = 'XX-01-00-00-00';
const result = findClosestTopic(topicCode, legalTopics);
expect(result).toBeUndefined();
});

it('handles cases with leading zeros in topic codes', () => {
const topicCode = 'FA-01-00-00-00';
const result = findClosestTopic(topicCode, legalTopics);
expect(result.name).toBe('Family');
});
});

0 comments on commit f7be4ce

Please sign in to comment.