package phpjx

import (
	"testing"

	_ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"

	"git.rosy.net.cn/baseapi/utils"
	"git.rosy.net.cn/jx-callback/business/model"
	"git.rosy.net.cn/jx-callback/business/partner"
	"git.rosy.net.cn/jx-callback/globals/testinit"
)

func init() {
	testinit.Init()
}

func TestBuildNewJxOrder(t *testing.T) {
	order, err := partner.CurOrderManager.LoadOrder("920931913000041", model.VendorIDJD)
	if err != nil {
		t.Fatal(err)
	}
	order.VendorID = model.VendorIDJX
	order.VendorStoreID = utils.Int2Str(order.StoreID)
	for _, sku := range order.Skus {
		sku.VendorID = model.VendorIDJX
		sku.VendorSkuID = utils.Int2Str(sku.SkuID)
	}
	order2 := &Data4Neworder{
		GoodsOrder: *order,
		Skus:       order.Skus,
	}
	msg := &CallbackMsg{
		AppKey:     appKey,
		MsgType:    MsgTypeOrder,
		SubMsgType: utils.Int2Str(model.OrderStatusNew),
		ThingID:    order.VendorOrderID,
		Data:       utils.Format4Output(order2, true),
	}
	t.Logf("\n%s", msg.AppKey)
	t.Logf("\n%s", msg.MsgType)
	t.Logf("\n%s", msg.SubMsgType)
	t.Logf("\n%s", msg.ThingID)
	t.Logf("\n%s", msg.Data)

	var order3 *model.GoodsOrder
	err = utils.UnmarshalUseNumber([]byte(msg.Data), &order3)
	if err != nil {
		t.Fatal(err)
	}
	t.Log(order3.OrderCreatedAt)
}
