package widetable

import (
	"log"
	"testing"
	"time"

	"github.com/pingcap/crm-bot/model"
	"github.com/pingcap/crm-bot/pkg/config"
	"github.com/stretchr/testify/assert"
)

func init() {
	config.InitConfig("config.yml", "yml", "../etc")
}
func TestTime(t *testing.T) {
	str := "2022-03-15T09:36:26.000+0000"
	d, err := time.Parse("2006-01-02T15:04:05.000-0700", str)
	if err != nil {
		panic(err)
	}
	log.Println(d)
}

func TestWideTable_New(t *testing.T) {
	wbg := NewWidetableManager()

	cfg := model.WidetableCfg{
		Name: "test",
		Path: "./etc/test.json",
	}
	wb := wbg.NewWidetable(cfg)
	assert.NotNil(t, wb)
	assert.Equal(t, "test", wb.TableName)
}

func TestWideTable_Flow(t *testing.T) {
	wbg := NewWidetableManager()
	cfg := model.WidetableCfg{
		Name: "test",
		Path: "./etc/test.json",
	}
	wb := wbg.NewWidetable(cfg)
	assert.NotNil(t, wb)

	wb.exists["3"] = "4"
	wb.Flow("Recrev", []map[string]interface{}{
		{
			"Id":        "1",
			"AccountId": "1",
			"RecrevId":  "2",
			"OrderId":   "3",
			"名字":        "1",
			"状态":        0,
			"Update":    "2022-04-12",
			"Cost":      5.55,
		},
	})

	sqls := <-wb.ch
	assert.NotEmpty(t, sqls)
	log.Println(sqls)
}
