package graph import ( "testing" "github.com/neo4j/neo4j-go-driver/v5/neo4j" "github.com/stretchr/testify/assert" ) func TestNodeConverter_ConvertNode(t *testing.T) { converter := NewNodeConverter() node := neo4j.Node{ Id: 1, Labels: []string{"Organization"}, Props: map[string]interface{}{ "id": "org_123", "name": "Test Organization", }, } pathNode := converter.ConvertNode(node) assert.Equal(t, "org_123", pathNode.ID) assert.Equal(t, []string{"Organization"}, pathNode.Labels) assert.Equal(t, "Test Organization", pathNode.Properties["name"]) } func TestNodeConverter_ConvertRelationship(t *testing.T) { converter := NewNodeConverter() rel := neo4j.Relationship{ Id: 1, Type: "MATCHES", Props: map[string]interface{}{ "distance_km": 10.5, "economic_value": 5000.0, }, } pathRel := converter.ConvertRelationship(rel) assert.Equal(t, "MATCHES", pathRel.Type) assert.Equal(t, 10.5, pathRel.Properties["distance_km"]) assert.Equal(t, 5000.0, pathRel.Properties["economic_value"]) } func TestNodeConverter_ConvertNodes(t *testing.T) { converter := NewNodeConverter() nodes := []interface{}{ neo4j.Node{ Id: 1, Labels: []string{"Organization"}, Props: map[string]interface{}{"id": "org_1"}, }, neo4j.Node{ Id: 2, Labels: []string{"Site"}, Props: map[string]interface{}{"id": "site_1"}, }, } pathNodes := converter.ConvertNodes(nodes) assert.Len(t, pathNodes, 2) assert.Equal(t, "org_1", pathNodes[0].ID) assert.Equal(t, "site_1", pathNodes[1].ID) } func TestNodeConverter_ConvertRelationships(t *testing.T) { converter := NewNodeConverter() rels := []interface{}{ neo4j.Relationship{ Id: 1, Type: "MATCHES", Props: map[string]interface{}{"distance_km": 5.0}, }, neo4j.Relationship{ Id: 2, Type: "HOSTS", Props: map[string]interface{}{}, }, } pathRels := converter.ConvertRelationships(rels) assert.Len(t, pathRels, 2) assert.Equal(t, "MATCHES", pathRels[0].Type) assert.Equal(t, "HOSTS", pathRels[1].Type) } func TestGetStringProp(t *testing.T) { props := map[string]interface{}{ "name": "Test", "id": "123", "count": 42, "nil_value": nil, "empty_value": "", } assert.Equal(t, "Test", getStringProp(props, "name")) assert.Equal(t, "123", getStringProp(props, "id")) assert.Equal(t, "", getStringProp(props, "count")) // Wrong type assert.Equal(t, "", getStringProp(props, "nil_value")) assert.Equal(t, "", getStringProp(props, "empty_value")) assert.Equal(t, "", getStringProp(props, "nonexistent")) } func TestGetFloat64Prop(t *testing.T) { props := map[string]interface{}{ "value": 123.45, "count": int64(42), "quantity": 100, "text": "not_a_number", "nil_value": nil, } assert.Equal(t, 123.45, getFloat64Prop(props, "value")) assert.Equal(t, 42.0, getFloat64Prop(props, "count")) assert.Equal(t, 100.0, getFloat64Prop(props, "quantity")) assert.Equal(t, 0.0, getFloat64Prop(props, "text")) assert.Equal(t, 0.0, getFloat64Prop(props, "nil_value")) assert.Equal(t, 0.0, getFloat64Prop(props, "nonexistent")) } func TestGetStringValue(t *testing.T) { assert.Equal(t, "test", getStringValue("test")) assert.Equal(t, "", getStringValue(nil)) assert.Equal(t, "", getStringValue(123)) } func TestGetFloat64Value(t *testing.T) { assert.Equal(t, 123.45, getFloat64Value(123.45)) assert.Equal(t, 42.0, getFloat64Value(int64(42))) assert.Equal(t, 100.0, getFloat64Value(100)) assert.Equal(t, 0.0, getFloat64Value(nil)) assert.Equal(t, 0.0, getFloat64Value("not_a_number")) } func TestGetIntValue(t *testing.T) { assert.Equal(t, 42, getIntValue(int64(42))) assert.Equal(t, 100, getIntValue(100)) assert.Equal(t, 50, getIntValue(50.7)) assert.Equal(t, 0, getIntValue(nil)) assert.Equal(t, 0, getIntValue("not_a_number")) }