mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-12 03:05:14 +00:00
Update threads to use model/store (#97)
This commit is contained in:
58
threads/handler/create_thread_test.go
Normal file
58
threads/handler/create_thread_test.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package handler_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/micro/services/threads/handler"
|
||||
pb "github.com/micro/services/threads/proto"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCreateThread(t *testing.T) {
|
||||
tt := []struct {
|
||||
Name string
|
||||
GroupID string
|
||||
Topic string
|
||||
Error error
|
||||
}{
|
||||
{
|
||||
Name: "MissingGroupID",
|
||||
Topic: "HelloWorld",
|
||||
Error: handler.ErrMissingGroupID,
|
||||
},
|
||||
{
|
||||
Name: "MissingTopic",
|
||||
GroupID: uuid.New().String(),
|
||||
Error: handler.ErrMissingTopic,
|
||||
},
|
||||
{
|
||||
Name: "Valid",
|
||||
GroupID: uuid.New().String(),
|
||||
Topic: "HelloWorld",
|
||||
},
|
||||
}
|
||||
|
||||
h := testHandler(t)
|
||||
for _, tc := range tt {
|
||||
t.Run(tc.Name, func(t *testing.T) {
|
||||
var rsp pb.CreateThreadResponse
|
||||
err := h.CreateThread(microAccountCtx(), &pb.CreateThreadRequest{
|
||||
Topic: tc.Topic, GroupId: tc.GroupID,
|
||||
}, &rsp)
|
||||
|
||||
assert.Equal(t, tc.Error, err)
|
||||
if tc.Error != nil {
|
||||
assert.Nil(t, rsp.Thread)
|
||||
return
|
||||
}
|
||||
|
||||
assertThreadsMatch(t, &pb.Thread{
|
||||
CreatedAt: handler.FormatTime(h.Time()),
|
||||
GroupId: tc.GroupID,
|
||||
Topic: tc.Topic,
|
||||
}, rsp.Thread)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user