turash/bugulma/backend/internal/graph/node_converter_test.go
Damir Mukimov 000eab4740
Major repository reorganization and missing backend endpoints implementation
Repository Structure:
- Move files from cluttered root directory into organized structure
- Create archive/ for archived data and scraper results
- Create bugulma/ for the complete application (frontend + backend)
- Create data/ for sample datasets and reference materials
- Create docs/ for comprehensive documentation structure
- Create scripts/ for utility scripts and API tools

Backend Implementation:
- Implement 3 missing backend endpoints identified in gap analysis:
  * GET /api/v1/organizations/{id}/matching/direct - Direct symbiosis matches
  * GET /api/v1/users/me/organizations - User organizations
  * POST /api/v1/proposals/{id}/status - Update proposal status
- Add complete proposal domain model, repository, and service layers
- Create database migration for proposals table
- Fix CLI server command registration issue

API Documentation:
- Add comprehensive proposals.md API documentation
- Update README.md with Users and Proposals API sections
- Document all request/response formats, error codes, and business rules

Code Quality:
- Follow existing Go backend architecture patterns
- Add proper error handling and validation
- Match frontend expected response schemas
- Maintain clean separation of concerns (handler -> service -> repository)
2025-11-25 06:01:16 +01:00

149 lines
3.8 KiB
Go

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"))
}