|
| 1 | +import { describe, it, expect } from "vitest"; |
| 2 | +import { |
| 3 | + composeActionExamples, |
| 4 | + formatActionNames, |
| 5 | + formatActions, |
| 6 | +} from "../actions"; |
| 7 | +import { Action } from "../types"; |
| 8 | + |
| 9 | +describe("actions", () => { |
| 10 | + const mockActions: Action[] = [ |
| 11 | + { |
| 12 | + name: "Action1", |
| 13 | + description: "First action description", |
| 14 | + similes: ["greeting", "welcoming"], |
| 15 | + examples: [ |
| 16 | + [ |
| 17 | + { |
| 18 | + user: "user", |
| 19 | + content: { |
| 20 | + text: "Hello {{user1}}!", |
| 21 | + action: "greet", |
| 22 | + }, |
| 23 | + }, |
| 24 | + ], |
| 25 | + ], |
| 26 | + handler: async () => {}, |
| 27 | + validate: async () => true, |
| 28 | + }, |
| 29 | + { |
| 30 | + name: "Action2", |
| 31 | + description: "Second action description", |
| 32 | + similes: ["talking", "conversing"], |
| 33 | + examples: [ |
| 34 | + [ |
| 35 | + { |
| 36 | + user: "user", |
| 37 | + content: { |
| 38 | + text: "{{user1}} talks to {{user2}}", |
| 39 | + action: null, |
| 40 | + }, |
| 41 | + }, |
| 42 | + ], |
| 43 | + ], |
| 44 | + handler: async () => {}, |
| 45 | + validate: async () => true, |
| 46 | + }, |
| 47 | + ]; |
| 48 | + |
| 49 | + describe("composeActionExamples", () => { |
| 50 | + it("should generate formatted examples with replaced usernames", () => { |
| 51 | + const result = composeActionExamples(mockActions, 2); |
| 52 | + |
| 53 | + expect(result).toBeTypeOf("string"); |
| 54 | + expect(result).toContain("user:"); |
| 55 | + expect(result).not.toContain("{{user1}}"); |
| 56 | + expect(result).not.toContain("{{user2}}"); |
| 57 | + }); |
| 58 | + |
| 59 | + it("should respect the count parameter", () => { |
| 60 | + const result = composeActionExamples(mockActions, 1); |
| 61 | + const examples = result |
| 62 | + .split("\n") |
| 63 | + .filter((line) => line.length > 0); |
| 64 | + expect(examples).toHaveLength(1); |
| 65 | + }); |
| 66 | + }); |
| 67 | + |
| 68 | + describe("formatActionNames", () => { |
| 69 | + it("should return comma-separated action names", () => { |
| 70 | + const result = formatActionNames(mockActions); |
| 71 | + |
| 72 | + expect(result).toBeTypeOf("string"); |
| 73 | + expect(result).toContain("Action1"); |
| 74 | + expect(result).toContain("Action2"); |
| 75 | + expect(result).toContain(", "); |
| 76 | + }); |
| 77 | + }); |
| 78 | + |
| 79 | + describe("formatActions", () => { |
| 80 | + it("should return formatted actions with descriptions", () => { |
| 81 | + const result = formatActions(mockActions); |
| 82 | + |
| 83 | + expect(result).toBeTypeOf("string"); |
| 84 | + expect(result).toContain("Action1: First action description"); |
| 85 | + expect(result).toContain("Action2: Second action description"); |
| 86 | + expect(result).toContain(",\n"); |
| 87 | + }); |
| 88 | + }); |
| 89 | +}); |
0 commit comments