@@ -81,22 +81,34 @@ func (suite *ActionItemServiceTestSuite) TestUpdateActionItem() {
81
81
err := CreateActionItem (suite .suiteCtx , createRequest )
82
82
assert .NoError (suite .T (), err )
83
83
84
- // For update, we need to use an existing ID
85
- // Since we can't easily get the ID from create, we'll use a known ID
84
+ // Get the created action item by listing items for the student in this phase
85
+ actionItems , err := ListActionItemsForStudentInPhase (suite .suiteCtx , suite .testCourseParticipationID , suite .testCoursePhaseID )
86
+ assert .NoError (suite .T (), err , "Should be able to list action items to find created item" )
87
+ assert .Greater (suite .T (), len (actionItems ), 0 , "Should have at least one action item" )
88
+
89
+ // Find the action item we just created
90
+ var createdActionItemID uuid.UUID
91
+ for _ , item := range actionItems {
92
+ if item .
Action == "Original action" && item .
Author == "[email protected] " {
93
+ createdActionItemID = item .ID
94
+ break
95
+ }
96
+ }
97
+ assert .NotEqual (suite .T (), uuid .Nil , createdActionItemID , "Should have found the created action item" )
98
+
99
+ // Now update the action item using the actual ID
86
100
updateRequest := actionItemDTO.UpdateActionItemRequest {
87
- ID : suite . testActionItemID ,
101
+ ID : createdActionItemID ,
88
102
CoursePhaseID : suite .testCoursePhaseID ,
89
103
CourseParticipationID : suite .testCourseParticipationID ,
90
104
Action : "Updated action" ,
91
105
92
106
}
93
107
94
- err = UpdateActionItem (suite .suiteCtx , updateRequest )
95
- assert .NoError (suite .T (), err , "Should be able to update action item" )
96
- // This might fail if the ID doesn't exist, which is expected
97
- // The test verifies the function doesn't panic
108
+ // Test the update operation with proper error handling
98
109
assert .NotPanics (suite .T (), func () {
99
- UpdateActionItem (suite .suiteCtx , updateRequest )
110
+ err := UpdateActionItem (suite .suiteCtx , updateRequest )
111
+ assert .NoError (suite .T (), err , "Should be able to update existing action item" )
100
112
}, "Should not panic when updating action item" )
101
113
}
102
114
@@ -107,7 +119,7 @@ func (suite *ActionItemServiceTestSuite) TestDeleteActionItem() {
107
119
// This might fail if the ID doesn't exist, which is expected
108
120
// The test verifies the function doesn't panic
109
121
assert .NotPanics (suite .T (), func () {
110
- DeleteActionItem (suite .suiteCtx , testID )
122
+ _ = DeleteActionItem (suite .suiteCtx , testID )
111
123
}, "Should not panic when deleting action item" )
112
124
}
113
125
@@ -119,7 +131,7 @@ func (suite *ActionItemServiceTestSuite) TestDeleteActionItemNonExistent() {
119
131
// This is because DELETE operations are idempotent in SQL
120
132
// We just verify it doesn't panic
121
133
assert .NotPanics (suite .T (), func () {
122
- DeleteActionItem (suite .suiteCtx , nonExistentID )
134
+ _ = DeleteActionItem (suite .suiteCtx , nonExistentID )
123
135
}, "Should not panic when deleting non-existent action item" )
124
136
}
125
137
0 commit comments