mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-15 12:34:44 +00:00
70
streams/handler/read_conversation_test.go
Normal file
70
streams/handler/read_conversation_test.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package handler_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/micro/services/streams/handler"
|
||||
pb "github.com/micro/services/streams/proto"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||
)
|
||||
|
||||
func TestReadConversation(t *testing.T) {
|
||||
h := testHandler(t)
|
||||
|
||||
// seed some data
|
||||
var cRsp pb.CreateConversationResponse
|
||||
err := h.CreateConversation(context.TODO(), &pb.CreateConversationRequest{
|
||||
Topic: "HelloWorld", GroupId: uuid.New().String(),
|
||||
}, &cRsp)
|
||||
if err != nil {
|
||||
t.Fatalf("Error creating conversation: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
tt := []struct {
|
||||
Name string
|
||||
ID string
|
||||
GroupID *wrapperspb.StringValue
|
||||
Error error
|
||||
Result *pb.Conversation
|
||||
}{
|
||||
{
|
||||
Name: "MissingID",
|
||||
Error: handler.ErrMissingID,
|
||||
},
|
||||
{
|
||||
Name: "IncorrectID",
|
||||
ID: uuid.New().String(),
|
||||
Error: handler.ErrNotFound,
|
||||
},
|
||||
{
|
||||
Name: "FoundUsingIDOnly",
|
||||
ID: cRsp.Conversation.Id,
|
||||
Result: cRsp.Conversation,
|
||||
},
|
||||
{
|
||||
Name: "IncorrectGroupID",
|
||||
ID: cRsp.Conversation.Id,
|
||||
Error: handler.ErrNotFound,
|
||||
GroupID: &wrapperspb.StringValue{Value: uuid.New().String()},
|
||||
},
|
||||
}
|
||||
for _, tc := range tt {
|
||||
t.Run(tc.Name, func(t *testing.T) {
|
||||
var rsp pb.ReadConversationResponse
|
||||
err := h.ReadConversation(context.TODO(), &pb.ReadConversationRequest{
|
||||
Id: tc.ID, GroupId: tc.GroupID,
|
||||
}, &rsp)
|
||||
assert.Equal(t, tc.Error, err)
|
||||
|
||||
if tc.Result == nil {
|
||||
assert.Nil(t, rsp.Conversation)
|
||||
} else {
|
||||
assertConversationsMatch(t, tc.Result, rsp.Conversation)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user