From c2bf5336db7c23f2c519740aa6f6eac15295cdd4 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 31 Jul 2025 23:07:03 +0000 Subject: [PATCH] Add unit tests for functions utility and string manipulation utils Co-authored-by: skylar-anderson --- app/__tests__/functions.test.ts | 24 +++++++++++++++++++ app/utils/__tests__/index.ts | 0 app/utils/__tests__/utils.test.ts | 38 +++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 app/__tests__/functions.test.ts create mode 100644 app/utils/__tests__/index.ts create mode 100644 app/utils/__tests__/utils.test.ts diff --git a/app/__tests__/functions.test.ts b/app/__tests__/functions.test.ts new file mode 100644 index 0000000..19e7829 --- /dev/null +++ b/app/__tests__/functions.test.ts @@ -0,0 +1,24 @@ +import { selectFunctions, runFunction, availableFunctions, FunctionName } from '../functions'; + +describe('Functions utility', () => { + it('selectFunctions returns meta definitions for provided function names', () => { + const names: FunctionName[] = ['searchWithBing', 'addMemory']; + const defs = selectFunctions(names); + expect(defs).toHaveLength(names.length); + // Ensure that the returned function definitions correspond to the requested names + const returnedNames = defs.map((d) => d.name); + names.forEach((n) => expect(returnedNames).toContain(n)); + }); + + it('runFunction throws an error for unknown function name', async () => { + await expect(runFunction('unknown_function', {})).rejects.toThrow('Unknown function'); + }); + + it('every entry in availableFunctions exposes meta and run', () => { + Object.entries(availableFunctions).forEach(([name, mod]) => { + expect(typeof mod.meta).toBe('object'); + expect(mod.meta.name).toBe(name); + expect(typeof mod.run).toBe('function'); + }); + }); +}); \ No newline at end of file diff --git a/app/utils/__tests__/index.ts b/app/utils/__tests__/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/app/utils/__tests__/utils.test.ts b/app/utils/__tests__/utils.test.ts new file mode 100644 index 0000000..a7d374a --- /dev/null +++ b/app/utils/__tests__/utils.test.ts @@ -0,0 +1,38 @@ +import { pluralize } from '../pluralize'; +import { capitalize } from '../capitalize'; + +describe('Utility functions', () => { + describe('pluralize', () => { + it('handles regular plurals', () => { + expect(pluralize('cat')).toBe('cats'); + expect(pluralize('dog')).toBe('dogs'); + }); + + it('adds "es" for s, sh, ch, x, z endings', () => { + expect(pluralize('bus')).toBe('buses'); + expect(pluralize('box')).toBe('boxes'); + expect(pluralize('church')).toBe('churches'); + }); + + it('replaces y with ies when appropriate', () => { + expect(pluralize('country')).toBe('countries'); + expect(pluralize('city')).toBe('cities'); + // Should not replace when preceded by a vowel + expect(pluralize('day')).toBe('days'); + }); + }); + + describe('capitalize', () => { + it('capitalizes the first character of a string', () => { + expect(capitalize('hello')).toBe('Hello'); + }); + + it('returns the same string when already capitalized', () => { + expect(capitalize('World')).toBe('World'); + }); + + it('handles empty strings gracefully', () => { + expect(capitalize('')).toBe(''); + }); + }); +}); \ No newline at end of file