mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-14 03:54:47 +00:00
60
streams/handler/create_conversation_test.go
Normal file
60
streams/handler/create_conversation_test.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package handler_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/micro/services/streams/handler"
|
||||
pb "github.com/micro/services/streams/proto"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCreateConversation(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.CreateConversationResponse
|
||||
err := h.CreateConversation(context.TODO(), &pb.CreateConversationRequest{
|
||||
Topic: tc.Topic, GroupId: tc.GroupID,
|
||||
}, &rsp)
|
||||
|
||||
assert.Equal(t, tc.Error, err)
|
||||
if tc.Error != nil {
|
||||
assert.Nil(t, rsp.Conversation)
|
||||
return
|
||||
}
|
||||
|
||||
assertConversationsMatch(t, &pb.Conversation{
|
||||
CreatedAt: timestamppb.New(h.Time()),
|
||||
GroupId: tc.GroupID,
|
||||
Topic: tc.Topic,
|
||||
}, rsp.Conversation)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user