Files
services/streams/handler/create_conversation_test.go
ben-toogood 47fe6b39ec Streams (#47)
* Streams Service (WIP)

* Complete Streams Service
2021-01-25 14:35:11 +00:00

61 lines
1.2 KiB
Go

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