1+ /**
2+ * Tests for goal creation functionality (createGoal/goal_set)
3+ */
4+
5+ import { describe , it , expect , vi , beforeEach , afterEach } from "vitest"
6+ import {
7+ createMockPluginContext ,
8+ createMockFileSystem ,
9+ setupMockFileSystem ,
10+ } from "./goal-test-setup.js"
11+ import { createGoalManagement } from "../index.js"
12+
13+ describe ( "GoalManagement - Goal Creation" , ( ) => {
14+ let mockFsContext : ReturnType < typeof createMockFileSystem >
15+ let mockContext : ReturnType < typeof createMockPluginContext >
16+
17+ beforeEach ( ( ) => {
18+ vi . useFakeTimers ( )
19+ mockFsContext = createMockFileSystem ( )
20+ setupMockFileSystem ( mockFsContext )
21+ mockContext = createMockPluginContext ( )
22+ vi . restoreAllMocks ( )
23+ } )
24+
25+ afterEach ( ( ) => {
26+ vi . useRealTimers ( )
27+ vi . restoreAllMocks ( )
28+ } )
29+
30+ it ( "should create a new goal with active status" , async ( ) => {
31+ const goalManagement = createGoalManagement ( mockContext , {
32+ goalsBasePath : mockFsContext . basePath ,
33+ } )
34+
35+ const goal = await goalManagement . createGoal (
36+ "session-123" ,
37+ "Complete the project setup" ,
38+ "All setup tasks are done"
39+ )
40+
41+ expect ( goal ) . toBeDefined ( )
42+ expect ( goal . title ) . toBe ( "Complete the project setup" )
43+ expect ( goal . done_condition ) . toBe ( "All setup tasks are done" )
44+ expect ( goal . status ) . toBe ( "active" )
45+ expect ( goal . created_at ) . toBeDefined ( )
46+ expect ( goal . completed_at ) . toBeNull ( )
47+ } )
48+
49+ it ( "should create a goal with optional description" , async ( ) => {
50+ const goalManagement = createGoalManagement ( mockContext , {
51+ goalsBasePath : mockFsContext . basePath ,
52+ } )
53+
54+ const goal = await goalManagement . createGoal (
55+ "session-123" ,
56+ "Build the feature" ,
57+ "Feature is deployed to production" ,
58+ "This is a detailed description of the goal"
59+ )
60+
61+ expect ( goal . description ) . toBe ( "This is a detailed description of the goal" )
62+ expect ( goal . title ) . toBe ( "Build the feature" )
63+ } )
64+
65+ it ( "should generate goal with ISO timestamp" , async ( ) => {
66+ const goalManagement = createGoalManagement ( mockContext , {
67+ goalsBasePath : mockFsContext . basePath ,
68+ } )
69+
70+ const goal = await goalManagement . createGoal (
71+ "session-123" ,
72+ "Test goal" ,
73+ "Test is passing"
74+ )
75+
76+ // Verify timestamp is valid ISO format
77+ const timestamp = new Date ( goal . created_at )
78+ expect ( timestamp . toISOString ( ) ) . toBe ( goal . created_at )
79+ expect ( timestamp . getTime ( ) ) . toBeGreaterThan ( 0 )
80+ } )
81+
82+ it ( "should store goal in file system" , async ( ) => {
83+ const goalManagement = createGoalManagement ( mockContext , {
84+ goalsBasePath : mockFsContext . basePath ,
85+ } )
86+
87+ await goalManagement . createGoal (
88+ "session-123" ,
89+ "Store this goal" ,
90+ "Goal is stored"
91+ )
92+
93+ // Verify writeFile was called
94+ const fs = await import ( "node:fs/promises" )
95+ expect ( fs . writeFile ) . toHaveBeenCalled ( )
96+ expect ( fs . mkdir ) . toHaveBeenCalled ( )
97+ } )
98+
99+ it ( "should return the created goal" , async ( ) => {
100+ const goalManagement = createGoalManagement ( mockContext , {
101+ goalsBasePath : mockFsContext . basePath ,
102+ } )
103+
104+ const goal = await goalManagement . createGoal (
105+ "session-123" ,
106+ "Returnable goal" ,
107+ "Goal can be returned"
108+ )
109+
110+ expect ( goal ) . toHaveProperty ( "title" )
111+ expect ( goal ) . toHaveProperty ( "done_condition" )
112+ expect ( goal ) . toHaveProperty ( "status" )
113+ expect ( goal ) . toHaveProperty ( "created_at" )
114+ expect ( goal ) . toHaveProperty ( "completed_at" )
115+ } )
116+ } )
0 commit comments