#include "PortaConnectionSubsystem.h"
#include "Misc/AutomationTest.h"
#include "PortaConnectionSubsystemTestObject.h"
#include "PortaUtils.h"

IMPLEMENT_SIMPLE_AUTOMATION_TEST(FPortaConnectionSubsystemObjectCallTest,
	"PortaInterface.PortaConnectionSubsystem.ObjectCallRoute",
	EAutomationTestFlags::EditorContext | EAutomationTestFlags::ProductFilter)

bool FPortaConnectionSubsystemObjectCallTest::RunTest(const FString& Parameters)
{
	TObjectPtr<UPortaConnectionSubsystemTestObject> TestObject = NewObject<UPortaConnectionSubsystemTestObject>();
	auto subsystem = PortaUtils::GetEngineSubsystem<UPortaConnectionSubsystem>();

	TMap<FString, FString> Params;

	auto Content = FString::Printf(TEXT("{\"objectPath\":\"%s\", \"functionName\":\"SetStringValue\", \"parameters\":{\"Val\":\"Foo\"}}"), *TestObject->GetPathName());
	subsystem->HandleObjectCallRoute(Params, Content, TEXT(""), TEXT("0"));

	Content = FString::Printf(TEXT("{\"objectPath\":\"%s\", \"functionName\":\"SetIntValue\", \"parameters\":{\"Val\":5}}"), *TestObject->GetPathName());
	subsystem->HandleObjectCallRoute(Params, Content, TEXT(""), TEXT("0"));

	UTEST_EQUAL("StringValue", TestObject->GetStringValue(), TEXT("Foo"));
	UTEST_EQUAL("IntValue", TestObject->GetIntValue(), 5);

	return true;
}
