package miniprogram

import (
	"testing"
)

func TestSendSubscribeMessage(t *testing.T) {
	res := new(AccessTokenResponse)
	err := GetAccessToken("", "", res)
	if err != nil {
		t.Errorf("获取 access_token 错误: %s", err.Error())
	}

	sendSubscribeMessageRequest := new(SendSubscribeMessageRequest)
	sendSubscribeMessageRequest.Touser = "onjlN4wrsGe09SdRrpl4D_FWBh0I"
	sendSubscribeMessageRequest.TemplateID = "9dCV3z7vRPBGm8iMtSXsD7ZVyUjld46w7HTH9zLnzWw"
	sendSubscribeMessageRequest.Page = "pages/contact/index"
	sendSubscribeMessageRequest.MiniprogramState = "trial"
	sendSubscribeMessageRequest.Lang = "zh_CN"
	sendSubscribeMessageRequest.Data.Thing1.Value = "测试"
	sendSubscribeMessageRequest.Data.Time2.Value = "2020-1-27"
	sendSubscribeMessageRequest.Data.Thing3.Value = "测试"

	sendSubscribeMessageResponse := new(SendSubscribeMessageResponse)
	err = SendSubscribeMessage(res.AccessToken, sendSubscribeMessageRequest, sendSubscribeMessageResponse)
	if err != nil {
		t.Error(err)
	}

	t.Logf("Errcode: %d", sendSubscribeMessageResponse.Errcode)
	t.Logf("Errmsg: %s", sendSubscribeMessageResponse.Errmsg)
}
