package dao

import (
	"testing"
	"time"

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

func TestGetEffectiveActStoreSkuInfo(t *testing.T) {
	type testData struct {
		ResultCount int

		ActID     int
		VendorIDs []int
		StoreIDs  []int
		SkuIDs    []int
		FromTime  time.Time
		ToTime    time.Time
	}
	for _, v := range []*testData{
		&testData{
			StoreIDs:    []int{100190},
			SkuIDs:      []int{23847},
			ResultCount: 1,
			FromTime:    utils.Str2Time("2019-08-06 12:34:56"),
			ToTime:      utils.Str2Time("2019-08-06 12:34:56"),
		},
	} {
		result, err := GetEffectiveActStoreSkuInfo(GetDB(), v.ActID, v.VendorIDs, model.ActTypeAll, v.StoreIDs, v.SkuIDs, v.FromTime, v.ToTime)
		if err != nil {
			t.Fatal(err)
		}
		if len(result) != v.ResultCount {
			t.Log(utils.Format4Output(result, false))
			t.Errorf("cond:%s, len(result):%d, v.ResultCount:%d", utils.Format4Output(v, false), len(result), v.ResultCount)
		}
	}
}

func TestUpdateActStatusByTime(t *testing.T) {
	_, err := UpdateActStatusByTime(GetDB(), time.Now().Add(-48*time.Hour))
	if err != nil {
		t.Fatal(err)
	}
}

func TestGetActStoreSkuVendorList(t *testing.T) {
	_, _, err := GetActStoreSkuVendorList(GetDB(), 18440, nil, nil, nil, "", 0, 0)
	if err != nil {
		t.Fatal(err)
	}
}
