implement relationship integration tests

This commit is contained in:
2025-04-24 15:08:34 +02:00
parent b5342a19ca
commit c8d68c5cc7
28 changed files with 323 additions and 83 deletions

View File

@@ -1,6 +1,6 @@
{
"id1": 1,
"id2": 3,
"id1": 7,
"id2": 6,
"type": "child",
"relationship": {
"verified": true,

View File

@@ -0,0 +1,10 @@
{
"id1": 6,
"id2": 7,
"type": "parent",
"relationship": {
"verified": false,
"notes": "Test notes asdasdasda",
"from": "2021-01-01"
}
}

View File

@@ -0,0 +1,10 @@
{
"id1": 7,
"id2": 8,
"type": "sibling",
"relationship": {
"verified": true,
"notes": "OwO",
"from": "2024-01-01"
}
}

View File

@@ -0,0 +1,11 @@
{
"id1": 5,
"id2": 8,
"type": "spouse",
"relationship": {
"verified": true,
"notes": "UwU",
"from": "2025-01-01",
"to": "2025-03-01"
}
}

View File

@@ -0,0 +1,5 @@
{
"relationship": {
"verified": false
}
}

View File

@@ -46,12 +46,12 @@ func CreatePersonTest(dbAdapterUri string, client *http.Client) func(t *testing.
func GetPersonById(dbAdapterUri string, client *http.Client) func(t *testing.T) {
return func(t *testing.T) {
url := dbAdapterUri + "/person/2"
url := dbAdapterUri + "/person/8"
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, url, http.NoBody)
require.NoError(t, err)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-User-ID", "3")
req.Header.Set("X-User-ID", "6")
// Send the request
resp, err := client.Do(req)
@@ -68,7 +68,7 @@ func GetPersonById(dbAdapterUri string, client *http.Client) func(t *testing.T)
_, ok := responseBody["Id"]
require.True(t, ok)
require.Equal(t, "Johannes", responseBody["Props"].(map[string]any)["first_name"])
require.Equal(t, "Jhon", responseBody["Props"].(map[string]any)["first_name"])
require.Equal(t, "Doe", responseBody["Props"].(map[string]any)["last_name"])
}
}

View File

@@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/require"
)
func GetFamilyTreeByIdTest(dbAdapterUri string, client *http.Client) func(t *testing.T) {
func GetFamilyTreeByIdTest(dbAdapterUri string, client *http.Client) func(t *testing.T) { //nolint:dupl,lll // won't fix this, as it is a test
return func(t *testing.T) {
url := dbAdapterUri + "/family-tree"
@@ -33,19 +33,19 @@ func GetFamilyTreeByIdTest(dbAdapterUri string, client *http.Client) func(t *tes
err = json.NewDecoder(resp.Body).Decode(&responseBody)
require.NoError(t, err)
require.Equal(t, 4, len(responseBody.People))
require.Equal(t, 4, len(responseBody.Relationships))
require.Len(t, responseBody.People, 4) //nolint:mnd // 4 people in the family tree
require.Len(t, responseBody.Relationships, 4) //nolint:mnd // 4 relationships in the family tree
}
}
func GetFamilyTreeWithSpousesByIdTest(dbAdapterUri string, client *http.Client) func(t *testing.T) {
func GetFamilyTreeWithSpousesByIdTest(dbAdapterUri string, client *http.Client) func(t *testing.T) { //nolint:dupl,lll // won't fix this, as it is a test
return func(t *testing.T) {
url := dbAdapterUri + "/family-tree-with-spouses"
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, url, http.NoBody)
require.NoError(t, err)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-User-ID", "3")
req.Header.Set("X-User-ID", "1")
// Send the request
resp, err := client.Do(req)
@@ -63,7 +63,7 @@ func GetFamilyTreeWithSpousesByIdTest(dbAdapterUri string, client *http.Client)
err = json.NewDecoder(resp.Body).Decode(&responseBody)
require.NoError(t, err)
require.Equal(t, 5, len(responseBody.People))
require.Equal(t, 6, len(responseBody.Relationships))
require.Len(t, responseBody.People, 5) //nolint:mnd // 5 people in the family tree
require.Len(t, responseBody.Relationships, 5) //nolint:mnd // 5 relationships in the family tree
}
}

View File

@@ -53,7 +53,7 @@ func getPersonByGoogleIdTest(dbAdapterUri string, client *http.Client) func(t *t
//go:embed payloads/create_person_with_invite_code.json
var create_person_with_invite_code []byte
func CreatePersonByGoogleIdAndInviteCodeTest(dbAdapterUri string, client *http.Client) func(t *testing.T) {
func CreatePersonByGoogleIdAndInviteCodeTest(dbAdapterUri string, client *http.Client) func(t *testing.T) { //nolint:dupl,lll // won't fix this, as it is a test
return func(t *testing.T) {
url := dbAdapterUri + "/person/google/test-google-id"
@@ -85,7 +85,7 @@ func CreatePersonByGoogleIdAndInviteCodeTest(dbAdapterUri string, client *http.C
//go:embed payloads/create_person.json
var create_person []byte
func createPersonByGoogleIdTest(dbAdapterUri string, client *http.Client) func(t *testing.T) {
func createPersonByGoogleIdTest(dbAdapterUri string, client *http.Client) func(t *testing.T) { //nolint:dupl,lll // won't fix this, as it is a test
return func(t *testing.T) {
url := dbAdapterUri + "/person/google/test-google-id"

View File

@@ -7,27 +7,41 @@ import (
"net/http"
"testing"
"github.com/neo4j/neo4j-go-driver/v5/neo4j/dbtype"
"github.com/stretchr/testify/require"
)
//go:embed payloads/create_relationship_child.json
var create_relationship_child []byte
func CreateRelationshipsTest(dbAdapterUri string, client *http.Client) func(t *testing.T) {
//go:embed payloads/create_relationship_parent.json
var create_relationship_parent []byte
//go:embed payloads/create_relationship_sibling.json
var create_relationship_sibling []byte
//go:embed payloads/create_relationship_spouse.json
var create_relationship_spouse []byte
func CreateRelationshipsTest(dbAdapterURI string, client *http.Client) func(t *testing.T) {
return func(t *testing.T) {
t.Run("CreateChildRelationship", CreateRelationshipTest(dbAdapterUri, &create_relationship_child, client))
t.Run("CreatePerson6", CreatePersonTest(dbAdapterURI, client))
t.Run("CreatePerson7", CreatePersonTest(dbAdapterURI, client))
t.Run("CreatePerson8", CreatePersonTest(dbAdapterURI, client))
t.Run("CreateChildRelationship", CreateRelationshipTest(dbAdapterURI, &create_relationship_child, client))
t.Run("CreateParentRelationship", CreateRelationshipTest(dbAdapterURI, &create_relationship_parent, client))
t.Run("CreateSiblingRelationship", CreateRelationshipTest(dbAdapterURI, &create_relationship_sibling, client))
t.Run("CreateSpouseRelationship", CreateRelationshipTest(dbAdapterURI, &create_relationship_spouse, client))
}
}
func CreateRelationshipTest(dbAdapterUri string, payload *[]byte, client *http.Client) func(t *testing.T) {
func CreateRelationshipTest(dbAdapterURI string, payload *[]byte, client *http.Client) func(t *testing.T) {
return func(t *testing.T) {
url := dbAdapterUri + "/relationship"
url := dbAdapterURI + "/relationship"
req, err := http.NewRequestWithContext(t.Context(), http.MethodPost, url, bytes.NewBuffer(*payload))
require.NoError(t, err)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-User-ID", "1")
req.Header.Set("X-User-ID", "0")
req.Header.Set("X-User-Name", "application/json")
// Send the request
@@ -35,7 +49,7 @@ func CreateRelationshipTest(dbAdapterUri string, payload *[]byte, client *http.C
require.NoError(t, err)
defer resp.Body.Close()
var responseBody []dbtype.Relationship
var responseBody []any
err = json.NewDecoder(resp.Body).Decode(&responseBody)
require.NoError(t, err)
@@ -47,14 +61,14 @@ func CreateRelationshipTest(dbAdapterUri string, payload *[]byte, client *http.C
func UpdateRelationship() {
}
func GetRelationship(dbAdapterUri string, client *http.Client) func(t *testing.T) {
func GetRelationshipTest(dbAdapterURI string, client *http.Client) func(t *testing.T) {
return func(t *testing.T) {
url := dbAdapterUri + "/relationship/2/1"
url := dbAdapterURI + "/relationship/5/8"
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, url, http.NoBody)
require.NoError(t, err)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-User-ID", "3")
req.Header.Set("X-User-ID", "5")
// Send the request
resp, err := client.Do(req)
@@ -68,11 +82,11 @@ func GetRelationship(dbAdapterUri string, client *http.Client) func(t *testing.T
// Validate the response
require.Equal(t, http.StatusOK, resp.StatusCode)
_, ok := responseBody["id"]
_, ok := responseBody["Id"]
require.True(t, ok)
require.Equal(t, 2, responseBody["Props"].(map[string]any)["start"])
require.Equal(t, 1, responseBody["Props"].(map[string]any)["end"])
require.Equal(t, "5", responseBody["StartElementId"])
require.Equal(t, "8", responseBody["EndElementId"])
}
}