mirror of
https://github.com/vcscsvcscs/GenerationsHeritage.git
synced 2025-08-14 14:59:07 +02:00
implement relationship integration tests
This commit is contained in:
@@ -38,7 +38,7 @@ var cypherKeywords = []string{
|
||||
"WHERE",
|
||||
}
|
||||
|
||||
var cypherOperators = []string{ //nolint: unused // this could be used in the future
|
||||
var cypherOperators = []string{ //nolint:unused // this could be used in the future
|
||||
"+",
|
||||
"-",
|
||||
"*",
|
||||
|
@@ -1,3 +1,3 @@
|
||||
MATCH (n)-[r]->(o)
|
||||
MATCH (n)-[r:Sibling|:Spouse|:Child|:Parent]->(o)
|
||||
WHERE id(n) = $id1 AND id(o) = $id2
|
||||
RETURN r as relationship
|
@@ -2,6 +2,7 @@ package memgraph
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
|
||||
"github.com/neo4j/neo4j-go-driver/v5/neo4j/dbtype"
|
||||
@@ -23,7 +24,12 @@ func GetRelationship(ctx context.Context, id1, id2 int) neo4j.ManagedTransaction
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return record.AsMap(), nil
|
||||
relationshipsRaw, ok := record.Get("relationship")
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("no relationships found")
|
||||
}
|
||||
|
||||
return relationshipsRaw, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +66,12 @@ func UpdateRelationship(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return record.AsMap(), nil
|
||||
relationshipRaw, ok := record.Get("relationship")
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("no relationships found")
|
||||
}
|
||||
|
||||
return relationshipRaw, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,11 +115,12 @@ func CreateChildParentRelationship(
|
||||
|
||||
siblingRecord, err := siblingResult.Single(ctx)
|
||||
if err != nil {
|
||||
|
||||
siblingRelationship, ok := siblingRecord.Get("relationships")
|
||||
siblings, ok := siblingRelationship.([]dbtype.Relationship)
|
||||
if ok {
|
||||
relationships = append(relationships, siblings...)
|
||||
siblings, ok := siblingRelationship.([]dbtype.Relationship)
|
||||
if ok {
|
||||
relationships = append(relationships, siblings...)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +143,17 @@ func CreateSiblingRelationship(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result.Collect(ctx)
|
||||
record, err := result.Single(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
relationshipsRaw, ok := record.Get("relationships")
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("no relationships found")
|
||||
}
|
||||
|
||||
return relationshipsRaw, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,6 +172,16 @@ func CreateSpouseRelationship(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result.Collect(ctx)
|
||||
record, err := result.Single(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
relationshipsRaw, ok := record.Get("relationships")
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("no relationships found")
|
||||
}
|
||||
|
||||
return relationshipsRaw, nil
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/vcscsvcscs/GenerationsHeritage/apps/db-adapter/pkg/api"
|
||||
)
|
||||
|
||||
func TestGetRelationship(t *testing.T) {
|
||||
func TestGetRelationships(t *testing.T) {
|
||||
testCases := []struct {
|
||||
mockTxSetup func() *mock.Transaction
|
||||
expectedResult map[string]any
|
||||
@@ -24,8 +24,8 @@ func TestGetRelationship(t *testing.T) {
|
||||
mockTx := new(mock.Transaction)
|
||||
mockResult := new(mock.Result)
|
||||
mockRecord := &neo4j.Record{
|
||||
Values: []any{"value"},
|
||||
Keys: []string{"key"},
|
||||
Values: []any{map[string]any{"key": "value"}},
|
||||
Keys: []string{"relationship"},
|
||||
}
|
||||
mockResult.On("Single", context.Background()).Return(mockRecord, nil)
|
||||
mockTx.On("Run", context.Background(), GetRelationshipCypherQuery, map[string]any{"id1": 1, "id2": 2}).Return(mockResult, nil)
|
||||
@@ -142,14 +142,14 @@ func TestUpdateRelationship(t *testing.T) {
|
||||
mockTx := new(mock.Transaction)
|
||||
mockResult := new(mock.Result)
|
||||
mockRecord := &neo4j.Record{
|
||||
Values: []any{"value"},
|
||||
Keys: []string{"key"},
|
||||
Values: []any{map[string]any{"key": "value"}},
|
||||
Keys: []string{"relationship"},
|
||||
}
|
||||
mockResult.On("Single", context.Background()).Return(mockRecord, nil)
|
||||
mockTx.On("Run", context.Background(), UpdateRelationshipCypherQuery, map[string]any{
|
||||
"id1": 1,
|
||||
"id2": 2,
|
||||
"relationship": api.FamilyRelationship{},
|
||||
"relationship": map[string]any{},
|
||||
}).Return(mockResult, nil)
|
||||
return mockTx
|
||||
},
|
||||
@@ -163,7 +163,7 @@ func TestUpdateRelationship(t *testing.T) {
|
||||
mockTx.On("Run", context.Background(), UpdateRelationshipCypherQuery, map[string]any{
|
||||
"id1": 1,
|
||||
"id2": 2,
|
||||
"relationship": api.FamilyRelationship{},
|
||||
"relationship": map[string]any{},
|
||||
}).Return(nil, errors.New("run error"))
|
||||
return mockTx
|
||||
},
|
||||
|
@@ -120,11 +120,11 @@ func processSlice(val reflect.Value) []any {
|
||||
if isPreservedType(item) {
|
||||
slice[i] = item
|
||||
} else if reflect.ValueOf(item).Kind() == reflect.Struct {
|
||||
switch item.(type) {
|
||||
switch typedItem := item.(type) {
|
||||
case openapi_types.Date:
|
||||
slice[i] = item.(openapi_types.Date).String()
|
||||
slice[i] = typedItem.String()
|
||||
default:
|
||||
slice[i] = StructToMap(item)
|
||||
slice[i] = StructToMap(typedItem)
|
||||
}
|
||||
} else {
|
||||
slice[i] = item
|
||||
|
Reference in New Issue
Block a user