@@ -110,6 +110,8 @@ func (p *bddPlugin) createScenario(req *plugin.Request, res *plugin.Response) {
110110 CreatedAt : now ,
111111 UpdatedAt : now ,
112112 }
113+ plugin .RecordActivity (taskID , projectID , req .Caller .UserID , "task.bdd_scenario.created" ,
114+ map [string ]any {"title" : b .Title })
113115 created (res , scenario )
114116}
115117
@@ -225,6 +227,22 @@ func (p *bddPlugin) updateScenario(req *plugin.Request, res *plugin.Response) {
225227 res .Error (404 , "bdd scenario not found" )
226228 return
227229 }
230+ // Collect which fields changed for the activity record.
231+ var changedFields []string
232+ if b .Title != nil && * b .Title != sc .str ("title" ) {
233+ changedFields = append (changedFields , "title" )
234+ }
235+ if b .Given != nil && * b .Given != sc .str ("given_text" ) {
236+ changedFields = append (changedFields , "given" )
237+ }
238+ if b .When != nil && * b .When != sc .str ("when_text" ) {
239+ changedFields = append (changedFields , "when" )
240+ }
241+ if b .Then != nil && * b .Then != sc .str ("then_text" ) {
242+ changedFields = append (changedFields , "then" )
243+ }
244+ plugin .RecordActivity (taskID , projectID , req .Caller .UserID , "task.bdd_scenario.updated" ,
245+ map [string ]any {"title" : updTitle , "changes" : changedFields })
228246 ok (res , bddScenario {
229247 ID : scenarioID ,
230248 TaskID : taskID ,
@@ -247,6 +265,23 @@ func (p *bddPlugin) deleteScenario(req *plugin.Request, res *plugin.Response) {
247265 return
248266 }
249267
268+ // Fetch title before deletion for the activity record.
269+ titleResult , err := p .db .Query (
270+ `SELECT title FROM bdd_scenarios WHERE id = $1 AND task_id = $2` ,
271+ scenarioID , taskID ,
272+ )
273+ if err != nil {
274+ p .log .Error ("deleteScenario title fetch: " + err .Error ())
275+ res .Error (500 , "failed to delete bdd scenario" )
276+ return
277+ }
278+ if len (titleResult .Rows ) == 0 {
279+ res .Error (404 , "bdd scenario not found" )
280+ return
281+ }
282+ scenarioTitleSC := newRowScanner (titleResult .Columns , titleResult .Rows [0 ])
283+ scenarioTitle := scenarioTitleSC .str ("title" )
284+
250285 affected , err := p .db .Exec (
251286 `DELETE FROM bdd_scenarios WHERE id = $1 AND task_id = $2` ,
252287 scenarioID , taskID ,
@@ -260,6 +295,8 @@ func (p *bddPlugin) deleteScenario(req *plugin.Request, res *plugin.Response) {
260295 res .Error (404 , "bdd scenario not found" )
261296 return
262297 }
298+ plugin .RecordActivity (taskID , projectID , req .Caller .UserID , "task.bdd_scenario.deleted" ,
299+ map [string ]any {"title" : scenarioTitle })
263300 res .NoContent ()
264301}
265302
0 commit comments