From 22b4182dc5bd984fc3ecad318befc4abb2c4da44 Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Thu, 20 Mar 2025 20:57:34 +0800 Subject: [PATCH] chore: add unit test --- .../packages/core/src/create-ai-function.test.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/legacy/packages/core/src/create-ai-function.test.ts b/legacy/packages/core/src/create-ai-function.test.ts index 63a3d26d..12771bc5 100644 --- a/legacy/packages/core/src/create-ai-function.test.ts +++ b/legacy/packages/core/src/create-ai-function.test.ts @@ -2,6 +2,7 @@ import { describe, expect, test } from 'vitest' import { z } from 'zod' import { createAIFunction } from './create-ai-function' +import { type Msg } from './message' const fullName = createAIFunction( { @@ -34,9 +35,22 @@ describe('createAIFunction()', () => { }) }) - test('executes the function', async () => { + test('executes the function with JSON string', async () => { expect(await fullName('{"first": "John", "last": "Doe"}')).toEqual( 'John Doe' ) }) + + test('executes the function with OpenAI Message', async () => { + const message: Msg.FuncCall = { + role: 'assistant', + content: null, + function_call: { + name: 'fullName', + arguments: '{"first": "Jane", "last": "Smith"}' + } + } + + expect(await fullName(message)).toEqual('Jane Smith') + }) })