@@ -247,8 +247,15 @@ const sampleGoal: Goal = {
247
247
} ;
248
248
249
249
describe ( "getGoals" , ( ) => {
250
+ let runtime : IAgentRuntime ;
251
+
250
252
beforeEach ( ( ) => {
251
- vi . clearAllMocks ( ) ;
253
+ runtime = {
254
+ agentId : "test-agent-id" as UUID ,
255
+ databaseAdapter : {
256
+ getGoals : vi . fn ( ) . mockResolvedValue ( [ ] ) ,
257
+ } as any ,
258
+ } as IAgentRuntime ;
252
259
} ) ;
253
260
254
261
it ( "retrieves goals successfully" , async ( ) => {
@@ -274,6 +281,26 @@ describe("getGoals", () => {
274
281
} )
275
282
) . rejects . toThrow ( "Failed to retrieve goals" ) ;
276
283
} ) ;
284
+
285
+ it ( "should handle empty goals list" , async ( ) => {
286
+ const mockRuntime = {
287
+ agentId : "test-agent-id" as UUID ,
288
+ databaseAdapter : {
289
+ getGoals : vi . fn ( ) . mockResolvedValue ( [ ] ) ,
290
+ } ,
291
+ } as unknown as IAgentRuntime ;
292
+
293
+ const roomId = "test-room" as UUID ;
294
+
295
+ await getGoals ( { runtime : mockRuntime , roomId } ) ;
296
+
297
+ expect ( mockRuntime . databaseAdapter . getGoals ) . toHaveBeenCalledWith ( {
298
+ agentId : "test-agent-id" ,
299
+ roomId,
300
+ onlyInProgress : true ,
301
+ count : 5 ,
302
+ } ) ;
303
+ } ) ;
277
304
} ) ;
278
305
279
306
describe ( "formatGoalsAsString" , ( ) => {
@@ -292,6 +319,53 @@ describe("formatGoalsAsString", () => {
292
319
const formatted = formatGoalsAsString ( { goals : [ ] } ) ;
293
320
expect ( formatted ) . toBe ( "" ) ;
294
321
} ) ;
322
+
323
+ it ( "should format goals as string correctly" , ( ) => {
324
+ const goals : Goal [ ] = [
325
+ {
326
+ id : "1" as UUID ,
327
+ name : "Goal 1" ,
328
+ status : GoalStatus . IN_PROGRESS ,
329
+ objectives : [
330
+ {
331
+ id : "obj1" as UUID ,
332
+ description : "Objective 1" ,
333
+ completed : true ,
334
+ } ,
335
+ {
336
+ id : "obj2" as UUID ,
337
+ description : "Objective 2" ,
338
+ completed : false ,
339
+ } ,
340
+ ] ,
341
+ roomId : "test-room" as UUID ,
342
+ userId : "test-user" as UUID ,
343
+ } ,
344
+ {
345
+ id : "2" as UUID ,
346
+ name : "Goal 2" ,
347
+ status : GoalStatus . DONE ,
348
+ objectives : [
349
+ {
350
+ id : "obj3" as UUID ,
351
+ description : "Objective 3" ,
352
+ completed : true ,
353
+ } ,
354
+ ] ,
355
+ roomId : "test-room" as UUID ,
356
+ userId : "test-user" as UUID ,
357
+ } ,
358
+ ] ;
359
+
360
+ const formattedGoals = formatGoalsAsString ( { goals } ) ;
361
+ expect ( formattedGoals ) . toContain ( "Goal: Goal 1" ) ;
362
+ expect ( formattedGoals ) . toContain ( "id: 1" ) ;
363
+ expect ( formattedGoals ) . toContain ( "- [x] Objective 1 (DONE)" ) ;
364
+ expect ( formattedGoals ) . toContain ( "- [ ] Objective 2 (IN PROGRESS)" ) ;
365
+ expect ( formattedGoals ) . toContain ( "Goal: Goal 2" ) ;
366
+ expect ( formattedGoals ) . toContain ( "id: 2" ) ;
367
+ expect ( formattedGoals ) . toContain ( "- [x] Objective 3 (DONE)" ) ;
368
+ } ) ;
295
369
} ) ;
296
370
297
371
describe ( "updateGoal" , ( ) => {
@@ -318,6 +392,138 @@ describe("updateGoal", () => {
318
392
updateGoal ( { runtime : mockRuntime , goal : sampleGoal } )
319
393
) . rejects . toThrow ( "Failed to update goal" ) ;
320
394
} ) ;
395
+
396
+ it ( "should update goal status correctly" , async ( ) => {
397
+ const goalId = "test-goal" as UUID ;
398
+ const mockRuntime = {
399
+ databaseAdapter : { updateGoal : vi . fn ( ) } ,
400
+ agentId : "test-agent-id" as UUID ,
401
+ } as unknown as IAgentRuntime ;
402
+
403
+ const updatedGoal : Goal = {
404
+ id : goalId ,
405
+ name : "Test Goal" ,
406
+ objectives : [
407
+ {
408
+ description : "Objective 1" ,
409
+ completed : false ,
410
+ } ,
411
+ {
412
+ description : "Objective 2" ,
413
+ completed : true ,
414
+ } ,
415
+ ] ,
416
+ roomId : "room-id" as UUID ,
417
+ userId : "user-id" as UUID ,
418
+ status : GoalStatus . DONE ,
419
+ } ;
420
+
421
+ await updateGoal ( {
422
+ runtime : mockRuntime ,
423
+ goal : updatedGoal ,
424
+ } ) ;
425
+
426
+ expect ( mockRuntime . databaseAdapter . updateGoal ) . toHaveBeenCalledWith ( updatedGoal ) ;
427
+ } ) ;
428
+
429
+ it ( "should handle failed goal update" , async ( ) => {
430
+ const goalId = "test-goal" as UUID ;
431
+ const mockRuntime = {
432
+ databaseAdapter : { updateGoal : vi . fn ( ) } ,
433
+ agentId : "test-agent-id" as UUID ,
434
+ } as unknown as IAgentRuntime ;
435
+
436
+ const updatedGoal : Goal = {
437
+ id : goalId ,
438
+ name : "Test Goal" ,
439
+ objectives : [
440
+ {
441
+ description : "Objective 1" ,
442
+ completed : false ,
443
+ } ,
444
+ {
445
+ description : "Objective 2" ,
446
+ completed : true ,
447
+ } ,
448
+ ] ,
449
+ roomId : "room-id" as UUID ,
450
+ userId : "user-id" as UUID ,
451
+ status : GoalStatus . FAILED ,
452
+ } ;
453
+
454
+ await updateGoal ( {
455
+ runtime : mockRuntime ,
456
+ goal : updatedGoal ,
457
+ } ) ;
458
+
459
+ expect ( mockRuntime . databaseAdapter . updateGoal ) . toHaveBeenCalledWith ( updatedGoal ) ;
460
+ } ) ;
461
+
462
+ it ( "should handle in-progress goal update" , async ( ) => {
463
+ const goalId = "test-goal" as UUID ;
464
+ const mockRuntime = {
465
+ databaseAdapter : { updateGoal : vi . fn ( ) } ,
466
+ agentId : "test-agent-id" as UUID ,
467
+ } as unknown as IAgentRuntime ;
468
+
469
+ const updatedGoal : Goal = {
470
+ id : goalId ,
471
+ name : "Test Goal" ,
472
+ objectives : [
473
+ {
474
+ description : "Objective 1" ,
475
+ completed : false ,
476
+ } ,
477
+ {
478
+ description : "Objective 2" ,
479
+ completed : true ,
480
+ } ,
481
+ ] ,
482
+ roomId : "room-id" as UUID ,
483
+ userId : "user-id" as UUID ,
484
+ status : GoalStatus . IN_PROGRESS ,
485
+ } ;
486
+
487
+ await updateGoal ( {
488
+ runtime : mockRuntime ,
489
+ goal : updatedGoal ,
490
+ } ) ;
491
+
492
+ expect ( mockRuntime . databaseAdapter . updateGoal ) . toHaveBeenCalledWith ( updatedGoal ) ;
493
+ } ) ;
494
+
495
+ it ( "should handle goal priority updates" , async ( ) => {
496
+ const goalId = "test-goal" as UUID ;
497
+ const mockRuntime = {
498
+ databaseAdapter : { updateGoal : vi . fn ( ) } ,
499
+ agentId : "test-agent-id" as UUID ,
500
+ } as unknown as IAgentRuntime ;
501
+
502
+ const updatedGoal : Goal = {
503
+ id : goalId ,
504
+ name : "Test Goal" ,
505
+ objectives : [
506
+ {
507
+ description : "Objective 1" ,
508
+ completed : false ,
509
+ } ,
510
+ {
511
+ description : "Objective 2" ,
512
+ completed : true ,
513
+ } ,
514
+ ] ,
515
+ roomId : "room-id" as UUID ,
516
+ userId : "user-id" as UUID ,
517
+ status : GoalStatus . IN_PROGRESS ,
518
+ } ;
519
+
520
+ await updateGoal ( {
521
+ runtime : mockRuntime ,
522
+ goal : updatedGoal ,
523
+ } ) ;
524
+
525
+ expect ( mockRuntime . databaseAdapter . updateGoal ) . toHaveBeenCalledWith ( updatedGoal ) ;
526
+ } ) ;
321
527
} ) ;
322
528
323
529
describe ( "createGoal" , ( ) => {
@@ -344,4 +550,57 @@ describe("createGoal", () => {
344
550
createGoal ( { runtime : mockRuntime , goal : sampleGoal } )
345
551
) . rejects . toThrow ( "Failed to create goal" ) ;
346
552
} ) ;
553
+
554
+ it ( "should create new goal with correct properties" , async ( ) => {
555
+ const newGoal : Goal = {
556
+ name : "New Goal" ,
557
+ roomId : "room-id" as UUID ,
558
+ userId : "user-id" as UUID ,
559
+ status : GoalStatus . IN_PROGRESS ,
560
+ objectives : [ ]
561
+ } ;
562
+
563
+ const mockRuntime = {
564
+ databaseAdapter : { createGoal : vi . fn ( ) } ,
565
+ agentId : "test-agent-id" as UUID ,
566
+ } as unknown as IAgentRuntime ;
567
+
568
+ await createGoal ( {
569
+ runtime : mockRuntime ,
570
+ goal : newGoal ,
571
+ } ) ;
572
+
573
+ expect ( mockRuntime . databaseAdapter . createGoal ) . toHaveBeenCalledWith (
574
+ expect . objectContaining ( {
575
+ name : "New Goal" ,
576
+ roomId : "room-id" ,
577
+ userId : "user-id" ,
578
+ status : GoalStatus . IN_PROGRESS ,
579
+ objectives : [ ]
580
+ } )
581
+ ) ;
582
+ } ) ;
583
+
584
+ it ( "should create a new goal" , async ( ) => {
585
+ const mockRuntime = {
586
+ databaseAdapter : { createGoal : vi . fn ( ) } ,
587
+ agentId : "test-agent-id" as UUID ,
588
+ } as unknown as IAgentRuntime ;
589
+
590
+ const newGoal = {
591
+ id : "new-goal" as UUID ,
592
+ name : "New Goal" ,
593
+ objectives : [ ] ,
594
+ roomId : "test-room" as UUID ,
595
+ userId : "test-user" as UUID ,
596
+ status : GoalStatus . IN_PROGRESS ,
597
+ } ;
598
+
599
+ await createGoal ( {
600
+ runtime : mockRuntime ,
601
+ goal : newGoal ,
602
+ } ) ;
603
+
604
+ expect ( mockRuntime . databaseAdapter . createGoal ) . toHaveBeenCalledWith ( newGoal ) ;
605
+ } ) ;
347
606
} ) ;
0 commit comments