package services

import (
	"testing"
	"time"
)

func TestKeepAwake(t *testing.T){
	t.Skip()
	ADD_TIME = 0
	ka := KeepAwake{}
	impl := &KeepAwakeImplementation{}
	ka.SetService(impl)

	testVin := "JH4KA7680RC01"
	// Check that trying to delete a non-existing set is okay
	err := impl.RemoveKeepAwakeMessage(testVin)
	if err != nil{
		t.Error(err)
	}
	client := RedisClientPool().GetFromPool()
	found, err := impl.checkRedisForCarEntry(testVin, client)
	if err != nil {
		t.Error(err)
	}
	if found{
		t.Error("did find expected vin when not supposed to")
	}
	client.Close()

	// Check we can successfully add
	err = impl.SendFirstKeepAwakeMessage(testVin)
	if err != nil{
		t.Error(err)
	}

	client = RedisClientPool().GetFromPool()
	found, err = impl.checkRedisForCarEntry(testVin, client)
	if err != nil {
		t.Error(err)
	}
	if !found{
		t.Error("did not find expected vin")
	}
	client.Close()

	time.Sleep(time.Second * 2)
	vins, err := impl.getKeepAwakeMessages()
	if err != nil{
		t.Error(err)
	}
	if len(vins) != 1{
		t.Error("len of vins wrong ", len(vins))
	}

	err = impl.RemoveKeepAwakeMessage(testVin)
	if err != nil{
		t.Error(err)
	}

	vins, err = impl.getKeepAwakeMessages()
	if err != nil{
		t.Error(err)
	}
	if len(vins) != 0{
		t.Error("len of vins wrong ", len(vins))
	}
}