diff --git a/internal/domain/monitor.go b/internal/domain/monitor.go index ffedeb2..260b307 100644 --- a/internal/domain/monitor.go +++ b/internal/domain/monitor.go @@ -18,7 +18,14 @@ type CreateMonitorParams struct { groupID string } -func NewCreateMonitorParams(tribeID int64, groupID string) (CreateMonitorParams, error) { +func NewCreateMonitorParams(groupID string, tribeID int64) (CreateMonitorParams, error) { + if groupID == "" { + return CreateMonitorParams{}, ValidationError{ + Field: "GroupID", + Err: ErrRequired, + } + } + if tribeID < tribeIDMin { return CreateMonitorParams{}, ValidationError{ Field: "TribeID", @@ -28,13 +35,6 @@ func NewCreateMonitorParams(tribeID int64, groupID string) (CreateMonitorParams, } } - if groupID == "" { - return CreateMonitorParams{}, ValidationError{ - Field: "GroupID", - Err: ErrRequired, - } - } - return CreateMonitorParams{tribeID: tribeID, groupID: groupID}, nil } diff --git a/internal/domain/monitor_test.go b/internal/domain/monitor_test.go index 7cc911c..de0a155 100644 --- a/internal/domain/monitor_test.go +++ b/internal/domain/monitor_test.go @@ -1,8 +1,66 @@ package domain_test -import "testing" +import ( + "testing" + + "gitea.dwysokinski.me/twhelp/dcbot/internal/domain" + "github.com/google/uuid" + "github.com/stretchr/testify/assert" +) func TestNewCreateMonitorParams(t *testing.T) { t.Parallel() + tests := []struct { + name string + tribeID int64 + groupID string + err error + }{ + { + name: "OK", + tribeID: 15, + groupID: uuid.NewString(), + }, + { + name: "ERR: GroupID cannot be blank", + groupID: "", + err: domain.ValidationError{ + Field: "GroupID", + Err: domain.ErrRequired, + }, + }, + { + name: "ERR: TribeID < 1", + groupID: uuid.NewString(), + tribeID: 0, + err: domain.ValidationError{ + Field: "TribeID", + Err: domain.MinError{ + Min: 1, + }, + }, + }, + } + + for _, tt := range tests { + tt := tt + + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + res, err := domain.NewCreateMonitorParams( + tt.groupID, + tt.tribeID, + ) + if tt.err != nil { + assert.ErrorIs(t, err, tt.err) + assert.Zero(t, res) + return + } + assert.NoError(t, err) + assert.Equal(t, tt.groupID, res.GroupID()) + assert.Equal(t, tt.tribeID, res.TribeID()) + }) + } }