feat: add a new command - /group monitor add

This commit is contained in:
Dawid Wysokiński 2022-10-22 06:44:41 +02:00
parent d6b2718d26
commit 7056290971
Signed by: Kichiyaki
GPG Key ID: B5445E357FB8B892
2 changed files with 67 additions and 9 deletions

View File

@ -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
}

View File

@ -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())
})
}
}