Skip to content

Commit a01404b

Browse files
authored
Fix/monitor partial update not update config (#194)
* refactor(monitor): update buildSetMapFromModel function to preserve created_at timestamp during updates * fix(monitor): handle monitor not found error in update operations for MongoDB and SQL repositories * feat(monitor): add support for partial updates with config field in UpdatePartial method
1 parent e934fda commit a01404b

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

apps/server/src/modules/monitor/monitor.service.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ func (mr *MonitorServiceImpl) UpdatePartial(ctx context.Context, id string, moni
177177
ResendInterval: monitor.ResendInterval,
178178
Active: monitor.Active,
179179
Status: monitor.Status,
180+
Config: monitor.Config,
181+
ProxyId: monitor.ProxyId,
182+
PushToken: monitor.PushToken,
180183
}
181184

182185
err := mr.monitorRepository.UpdatePartial(ctx, id, model)

apps/server/src/modules/monitor/monitor.service_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,35 @@ func TestMonitorService_UpdatePartial(t *testing.T) {
502502
// EventBus should not be called when noPublish is true
503503
})
504504

505+
t.Run("successful partial update with config field", func(t *testing.T) {
506+
service, mockRepo, _, _, _, _, _, _ := setupMonitorService()
507+
monitorID := "monitor123"
508+
config := "{\"host\":\"example.com\",\"port\":8080}"
509+
updateDto := &PartialUpdateDto{
510+
Config: &config,
511+
}
512+
513+
expectedModel := &Model{
514+
ID: monitorID,
515+
Name: "Test Monitor",
516+
Config: config,
517+
}
518+
519+
mockRepo.On("UpdatePartial", ctx, monitorID, mock.MatchedBy(func(m *UpdateModel) bool {
520+
return *m.ID == monitorID &&
521+
m.Config != nil &&
522+
*m.Config == config
523+
})).Return(nil)
524+
525+
mockRepo.On("FindByID", ctx, monitorID).Return(expectedModel, nil)
526+
527+
result, err := service.UpdatePartial(ctx, monitorID, updateDto, false)
528+
529+
assert.NoError(t, err)
530+
assert.Equal(t, expectedModel, result)
531+
mockRepo.AssertExpectations(t)
532+
})
533+
505534
t.Run("update error", func(t *testing.T) {
506535
service, mockRepo, _, _, _, _, _, _ := setupMonitorService()
507536
monitorID := "monitor123"

0 commit comments

Comments
 (0)