package weimobapi

import (
	"testing"

	"git.rosy.net.cn/baseapi"
	"git.rosy.net.cn/baseapi/utils"
	"go.uber.org/zap"
)

var (
	api         *API
	sugarLogger *zap.SugaredLogger
)

func init() {
	logger, _ := zap.NewDevelopment()
	sugarLogger = logger.Sugar()
	baseapi.Init(sugarLogger)

	tokenStr := `
	{"token_type":"bearer","access_token":"4c170b37-e70b-4fc0-aa03-d02fc1ebf43d","expires_in":7199,"refresh_token":"7b961b6b-0dc4-43e1-8c38-a9a10e2e130d","refresh_token_expires_in":607932,"scope":"default","public_account_id":"100000386048","business_id":"1224609670"}

	`
	var token *TokenInfo
	if err := utils.UnmarshalUseNumber([]byte(tokenStr), &token); err != nil {
		panic(err)
	}
	// prod
	api = New(token, "319F5E7FB6784DFCA3684C9333EB7744", "7267AA7F58261F6965599218F5A1D592")
}

func TestRefreshTokenByCode(t *testing.T) {
	result, err := api.RefreshTokenByCode("6Stxtw", "http://callback.test.jxc4.com/weimob/coded")
	if err != nil {
		t.Fatal(err)
	}
	baseapi.SugarLogger.Debug(utils.Format4Output(result, false))
}

func TestRefreshTokenByRefreshToken(t *testing.T) {
	result, err := api.RefreshTokenByRefreshToken()
	if err != nil {
		t.Fatal(err)
	}
	baseapi.SugarLogger.Debug(utils.Format4Output(result, false))
}
