mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-14 20:14:47 +00:00
codes
This commit is contained in:
@@ -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",
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user