package nodes

import (
	"github.com/robertkrimen/otto"
	"testing"
)

func TestGenScript(t *testing.T) {
	result := generateRuleNodeScript("filter", "return metadata.id===2")
	t.Log(result)
	vm := otto.New()
	_, err := vm.Run(result)
	if err != nil {
		t.Error(err)
	}
	call, err := vm.Call("filter", nil, `{"device_id":1,"heart_beat":{"device_id":20274757167}}`, `{"id":2}`, "")
	if err != nil {
		t.Error(err)
	}
	v, err := call.ToBoolean()
	if err != nil {
		t.Error(err)
	}
	t.Logf("%+v", v)

}
