This commit is contained in:
Dominic Wong
2021-03-25 22:53:48 +00:00
parent 81252c1611
commit 72aca7ee64
8 changed files with 56 additions and 35 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"testing"
"github.com/micro/micro/v3/service/auth"
"github.com/micro/services/codes/handler"
pb "github.com/micro/services/codes/proto"
"github.com/stretchr/testify/assert"
@@ -15,21 +16,21 @@ func TestCreate(t *testing.T) {
t.Run("MissingIdentity", func(t *testing.T) {
var rsp pb.CreateResponse
err := h.Create(context.TODO(), &pb.CreateRequest{}, &rsp)
err := h.Create(microAccountCtx(), &pb.CreateRequest{}, &rsp)
assert.Equal(t, handler.ErrMissingIdentity, err)
assert.Empty(t, rsp.Code)
})
t.Run("NoExpiry", func(t *testing.T) {
var rsp pb.CreateResponse
err := h.Create(context.TODO(), &pb.CreateRequest{Identity: "07503196715"}, &rsp)
err := h.Create(microAccountCtx(), &pb.CreateRequest{Identity: "07503196715"}, &rsp)
assert.NoError(t, err)
assert.NotEmpty(t, rsp.Code)
})
t.Run("WithExpiry", func(t *testing.T) {
var rsp pb.CreateResponse
err := h.Create(context.TODO(), &pb.CreateRequest{
err := h.Create(microAccountCtx(), &pb.CreateRequest{
Identity: "demo@m3o.com",
ExpiresAt: timestamppb.Now(),
}, &rsp)
@@ -37,3 +38,9 @@ func TestCreate(t *testing.T) {
assert.NotEmpty(t, rsp.Code)
})
}
func microAccountCtx() context.Context {
return auth.ContextWithAccount(context.TODO(), &auth.Account{
Issuer: "micro",
})
}