From f7be4cee69df69f3e46b464ae036d194fab5a561 Mon Sep 17 00:00:00 2001 From: jtmst Date: Mon, 20 May 2024 15:41:53 -0400 Subject: [PATCH] test --- src/data/helpers/index.test.ts | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/data/helpers/index.test.ts diff --git a/src/data/helpers/index.test.ts b/src/data/helpers/index.test.ts new file mode 100644 index 0000000..cd1f399 --- /dev/null +++ b/src/data/helpers/index.test.ts @@ -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'); + }); +});