商城c端前端
This commit is contained in:
@@ -12,11 +12,14 @@ import (
|
||||
)
|
||||
|
||||
type fakeRepository struct {
|
||||
config json.RawMessage
|
||||
account *store.PaymentAccount
|
||||
channel *store.WithdrawalChannel
|
||||
wallet *store.WithdrawalWallet
|
||||
orders []store.WithdrawalOrder
|
||||
config json.RawMessage
|
||||
account *store.PaymentAccount
|
||||
channel *store.WithdrawalChannel
|
||||
wallet *store.WithdrawalWallet
|
||||
orders []store.WithdrawalOrder
|
||||
rechargeChannels []store.RechargeChannel
|
||||
rechargeOrders []store.RechargeOrder
|
||||
createdRecharge store.RechargeCreation
|
||||
}
|
||||
|
||||
func (f *fakeRepository) CurrentSiteConfig(context.Context, int64) (json.RawMessage, error) {
|
||||
@@ -49,6 +52,21 @@ func (f *fakeRepository) WithdrawalOrders(context.Context, int64, int64, int, in
|
||||
func (f *fakeRepository) WithdrawalOrder(context.Context, int64, int64, int64) (*store.WithdrawalOrder, error) {
|
||||
return nil, errors.New("not implemented")
|
||||
}
|
||||
func (f *fakeRepository) RechargeChannels(context.Context, int64) ([]store.RechargeChannel, error) {
|
||||
return f.rechargeChannels, nil
|
||||
}
|
||||
func (f *fakeRepository) CreateRecharge(_ context.Context, input store.RechargeCreation) (*store.RechargeOrder, error) {
|
||||
f.createdRecharge = input
|
||||
return &store.RechargeOrder{ID: 8, RechargeNo: input.RechargeNo, ChannelID: input.ChannelID,
|
||||
ChannelName: "人工审核", RequestAmount: input.RequestAmount, Currency: input.Currency,
|
||||
Status: 1, Remark: input.Remark}, nil
|
||||
}
|
||||
func (f *fakeRepository) RechargeOrders(context.Context, int64, int64, int, int, int) (*store.RechargePage, error) {
|
||||
return &store.RechargePage{Items: f.rechargeOrders, Total: int64(len(f.rechargeOrders))}, nil
|
||||
}
|
||||
func (f *fakeRepository) RechargeOrder(context.Context, int64, int64, int64) (*store.RechargeOrder, error) {
|
||||
return nil, errors.New("not implemented")
|
||||
}
|
||||
|
||||
func TestQuoteCalculatesRateFeeAndLimits(t *testing.T) {
|
||||
repository := &fakeRepository{config: json.RawMessage(`{"features":{"withdrawal_enabled":true}}`),
|
||||
@@ -105,6 +123,40 @@ func TestWithdrawalStatusValidation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateRechargeValidatesChannelAndMapsOrder(t *testing.T) {
|
||||
repository := &fakeRepository{rechargeChannels: []store.RechargeChannel{{
|
||||
ID: 4, Code: "manual", Name: "人工审核", MinAmount: 100, MaxAmount: 100000,
|
||||
}}}
|
||||
service := &Service{repository: repository, ready: true, now: time.Now}
|
||||
result, err := service.CreateRecharge(context.Background(), 0, 9, CreateRechargeInput{
|
||||
ChannelID: 4, Amount: 50000, Currency: "cny", Remark: "测试",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result.Status != "pending_payment" || result.RequestAmount != 50000 ||
|
||||
repository.createdRecharge.MemberID != 9 || repository.createdRecharge.Currency != "CNY" {
|
||||
t.Fatalf("unexpected recharge: %#v, creation: %#v", result, repository.createdRecharge)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRechargeOrdersMapsStatusAndPagination(t *testing.T) {
|
||||
repository := &fakeRepository{rechargeOrders: []store.RechargeOrder{{
|
||||
ID: 3, RechargeNo: "RC3", RequestAmount: 20000, Currency: "CNY", Status: 3,
|
||||
}}}
|
||||
service := &Service{repository: repository, ready: true, now: time.Now}
|
||||
result, err := service.RechargeOrders(context.Background(), 0, 9, 1, 20, "succeeded")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result.Total != 1 || len(result.Items) != 1 || result.Items[0].Status != "succeeded" || result.HasNext {
|
||||
t.Fatalf("unexpected recharge page: %#v", result)
|
||||
}
|
||||
if _, err = service.RechargeOrders(context.Background(), 0, 9, 1, 20, "invalid"); !errors.Is(err, ErrRechargeStatusInvalid) {
|
||||
t.Fatalf("expected recharge status error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeterministicNumberIsStableAndScoped(t *testing.T) {
|
||||
first := deterministicNumber("WD", 0, 1, "request-key")
|
||||
if first != deterministicNumber("WD", 0, 1, "request-key") || first == deterministicNumber("WD", 0, 2, "request-key") {
|
||||
|
||||
Reference in New Issue
Block a user