增加短信渠道
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
biz "kra/internal/biz/integration"
|
||||
"kra/internal/service/dto"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type smsSenderFake struct{ calls int }
|
||||
|
||||
func (f *smsSenderFake) Send(context.Context, *biz.SMSMessage) (*biz.SMSResult, error) {
|
||||
f.calls++
|
||||
return &biz.SMSResult{MessageID: "test"}, nil
|
||||
}
|
||||
|
||||
func TestSMSRejectsInvalidInputBeforeDelivery(t *testing.T) {
|
||||
fake := &smsSenderFake{}
|
||||
s := &SMSService{uc: fake}
|
||||
for _, tt := range []struct{ provider, phone, params string }{
|
||||
{"aliyun", "+8613800138000", `[]`}, {"tencent", "+8613800138000", `{}`},
|
||||
{"tencent", "+8613800138000", `null`}, {"tencent", "+8613800138000", `[123]`},
|
||||
{"tencent", "+8613800138000", `[null]`}, {"aliyun", "+8613800138000", `{"code":null}`},
|
||||
{"aliyun", "13800138000", `{}`}, {"aliyun", "+12025550123", `{}`},
|
||||
{"aliyun", "+8613800138000,+8613800138001", `{}`}, {"other", "+8613800138000", `{}`},
|
||||
} {
|
||||
if _, err := s.Send(context.Background(), tt.provider, &dto.SMSSendRequest{Phone: tt.phone, Params: json.RawMessage(tt.params)}); err == nil {
|
||||
t.Fatalf("accepted invalid input: %+v", tt)
|
||||
}
|
||||
}
|
||||
if fake.calls != 0 {
|
||||
t.Fatal("invalid input reached sender")
|
||||
}
|
||||
for _, provider := range []string{"aliyun", "tencent"} {
|
||||
params := `{}`
|
||||
if provider == "tencent" {
|
||||
params = `[]`
|
||||
}
|
||||
if _, err := s.Send(context.Background(), provider, &dto.SMSSendRequest{Phone: "+8613800138000", Params: json.RawMessage(params)}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user