package data

import (
	"context"
	"fmt"
	"github.com/wechatpay-apiv3/wechatpay-go/core"
	"github.com/wechatpay-apiv3/wechatpay-go/services/cashcoupons"
	"testing"
)

func TestGetClient(t *testing.T) {
	server := &Server{
		MchID:                      "1605446142", // 证书所属商户 蓝色兄弟服务商立减金配置
		MchCertificateSerialNumber: "4D081089DEB385316CBDCB55C070287E4920AC76",
	}
	stockId := ""
	stockCreatorMchid := ""

	ctx := context.Background()

	client, err := GetClient(ctx, server)
	if err != nil {
		t.Error(err)
		return
	}

	svc := cashcoupons.StockApiService{Client: client}

	response, result, err := svc.QueryStock(ctx, cashcoupons.QueryStockRequest{
		StockId:           core.String(stockId),
		StockCreatorMchid: core.String(stockCreatorMchid),
	})

	if err != nil {
		t.Error(err)
		return
	}

	if result.Response.StatusCode != 200 {
		err = fmt.Errorf("查询活动微信返回错误StatusCode[%d]Status[%s]", result.Response.StatusCode, result.Response.Status)
		t.Error(err)
		return
	}

	t.Log(response)
}
