package domain

import (
	"fmt"
	"github.com/fonchain_enterprise/micro-account/pkg/cache"
	"github.com/fonchain_enterprise/micro-account/pkg/common/redis_key"
	"testing"
)

func TestCheckMsg(t *testing.T) {

	config := cache.RedisConfig{
		RedisDB:     "2",
		RedisAddr:   "127.0.0.1:6379",
		RedisPw:     "",
		RedisDbName: "2",
	}

	cache.LoadRedis(config)

	key := redis_key.GetAccountKeyCountTodayHour("test", "18205052627", "")
	//key := redis_key.GetAccountKeyCountToday("test", "18205052627")

	//没有字段
	cache.RedisClient.Del(key)

	if err := CheckMsg(key); err != nil {
		t.Errorf("验证不通过 :%s", err.Error())
	}

	//字段数字小于10
	/*
		cache.RedisClient.Set(key, 8, 0)
		if err := CheckMsg(key); err != nil {
			t.Errorf("验证不通过: %s", err.Error())
		}

	*/

	cache.RedisClient.Set(key, 11, 0)
	if err := CheckMsg(key); err == nil {
		t.Errorf("验证不通过:超过设定参数，没有提示")
	}

}

func TestInBlockList(t *testing.T) {
	config := cache.RedisConfig{
		RedisDB:     "2",
		RedisAddr:   "127.0.0.1:6379",
		RedisPw:     "",
		RedisDbName: "2",
	}

	cache.LoadRedis(config)
	type args struct {
		domain string
		tel    string
	}
	tests := []struct {
		name string
		args args
		want bool
	}{
		// TODO: Add test cases.
		{args: args{domain: "test", tel: "18205052627"}, want: true},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if InBlockList(tt.args.domain, tt.args.tel) == true {
				fmt.Println("黑名单")
			} else {
				fmt.Println("白名单")
			}

		})
	}
}
