mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-13 19:45:26 +00:00
Update threads to use model/store (#97)
This commit is contained in:
68
threads/handler/read_thread_test.go
Normal file
68
threads/handler/read_thread_test.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package handler_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/micro/services/threads/handler"
|
||||
pb "github.com/micro/services/threads/proto"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestReadThread(t *testing.T) {
|
||||
h := testHandler(t)
|
||||
|
||||
// seed some data
|
||||
var cRsp pb.CreateThreadResponse
|
||||
err := h.CreateThread(microAccountCtx(), &pb.CreateThreadRequest{
|
||||
Topic: "HelloWorld", GroupId: uuid.New().String(),
|
||||
}, &cRsp)
|
||||
if err != nil {
|
||||
t.Fatalf("Error creating thread: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
tt := []struct {
|
||||
Name string
|
||||
ID string
|
||||
GroupID string
|
||||
Error error
|
||||
Result *pb.Thread
|
||||
}{
|
||||
{
|
||||
Name: "MissingID",
|
||||
Error: handler.ErrMissingID,
|
||||
},
|
||||
{
|
||||
Name: "IncorrectID",
|
||||
ID: uuid.New().String(),
|
||||
Error: handler.ErrNotFound,
|
||||
},
|
||||
{
|
||||
Name: "FoundUsingIDOnly",
|
||||
ID: cRsp.Thread.Id,
|
||||
Result: cRsp.Thread,
|
||||
},
|
||||
{
|
||||
Name: "IncorrectGroupID",
|
||||
ID: cRsp.Thread.Id,
|
||||
Error: handler.ErrNotFound,
|
||||
GroupID: uuid.New().String(),
|
||||
},
|
||||
}
|
||||
for _, tc := range tt {
|
||||
t.Run(tc.Name, func(t *testing.T) {
|
||||
var rsp pb.ReadThreadResponse
|
||||
err := h.ReadThread(microAccountCtx(), &pb.ReadThreadRequest{
|
||||
Id: tc.ID, GroupId: tc.GroupID,
|
||||
}, &rsp)
|
||||
assert.Equal(t, tc.Error, err)
|
||||
|
||||
if tc.Result == nil {
|
||||
assert.Nil(t, rsp.Thread)
|
||||
} else {
|
||||
assertThreadsMatch(t, tc.Result, rsp.Thread)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user