implement integration test for relationship update and delete

This commit is contained in:
2025-04-24 16:06:20 +02:00
parent c8d68c5cc7
commit cd2116622f
10 changed files with 96 additions and 16 deletions

View File

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

View File

@@ -42,7 +42,6 @@ func CreateRelationshipTest(dbAdapterURI string, payload *[]byte, client *http.C
require.NoError(t, err)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-User-ID", "0")
req.Header.Set("X-User-Name", "application/json")
// Send the request
resp, err := client.Do(req)
@@ -58,7 +57,30 @@ func CreateRelationshipTest(dbAdapterURI string, payload *[]byte, client *http.C
}
}
func UpdateRelationship() {
//go:embed payloads/verify_relationship.json
var verify_relationship []byte
func UpdateRelationshipTest(dbAdapterURI string, client *http.Client) func(t *testing.T) {
return func(t *testing.T) {
url := dbAdapterURI + "/relationship/6/7"
req, err := http.NewRequestWithContext(t.Context(), http.MethodPatch, url, bytes.NewBuffer(verify_relationship))
require.NoError(t, err)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-User-ID", "7")
// Send the request
resp, err := client.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
var responseBody []any
err = json.NewDecoder(resp.Body).Decode(&responseBody)
require.NoError(t, err)
// Validate the response
require.Equal(t, http.StatusOK, resp.StatusCode)
}
}
func GetRelationshipTest(dbAdapterURI string, client *http.Client) func(t *testing.T) {
@@ -90,5 +112,27 @@ func GetRelationshipTest(dbAdapterURI string, client *http.Client) func(t *testi
}
}
func DeleteRelationship() {
func DeleteRelationshipTest(dbAdapterURI string, client *http.Client) func(t *testing.T) {
return func(t *testing.T) {
url := dbAdapterURI + "/relationship/5/8"
req, err := http.NewRequestWithContext(t.Context(), http.MethodDelete, url, http.NoBody)
require.NoError(t, err)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-User-ID", "5")
// Send the request
resp, err := client.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
var responseBody map[string]any
err = json.NewDecoder(resp.Body).Decode(&responseBody)
require.NoError(t, err)
// Validate the response
require.Equal(t, http.StatusOK, resp.StatusCode)
_, ok := responseBody["msg"]
require.True(t, ok)
}
}

View File

@@ -90,8 +90,8 @@ func (srv *server) UpdateRelationship(c *gin.Context, id1, id2 int, params api.U
actx, aCancel := context.WithTimeout(c.Request.Context(), srv.dbOpTimeout)
defer aCancel()
if err := auth.CouldManagePersonUnknownAdmin(actx, session, *relationship.Id1, params.XUserID); err != nil {
if err := auth.CouldManagePersonUnknownAdmin(actx, session, *relationship.Id2, params.XUserID); err != nil {
if err := auth.CouldManagePersonUnknownAdmin(actx, session, id1, params.XUserID); err != nil {
if err := auth.CouldManagePersonUnknownAdmin(actx, session, id2, params.XUserID); err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"msg": fmt.Sprint("User does not have access to this person", err.Error())})
return

View File

@@ -1,3 +1,3 @@
MATCH (a:Person)-[r]-(b:Person)
WHERE id(a) = $id1 AND id(b) = $id2 AND type(r) != Admin
WHERE id(a) = $id1 AND id(b) = $id2 AND type(r) <> "Admin"
DELETE r;

View File

@@ -1,4 +1,4 @@
MATCH (n)-[r]->(o)
WHERE id(n) = $id1 AND id(o) = $id2
SET r += $relationship
RETURN r as relationship
RETURN collect(r) as relationship

View File

@@ -118,5 +118,7 @@ func IntegrationTestFlow(dbAdapterURI string) func(t *testing.T) {
t.Run("GetPersonById", integration_tests.GetPersonById(dbAdapterURI, client))
t.Run("GetFamilyTreeByIdTest", integration_tests.GetFamilyTreeByIdTest(dbAdapterURI, client))
t.Run("GetFamilyTreeWithSpousesByIdTest", integration_tests.GetFamilyTreeWithSpousesByIdTest(dbAdapterURI, client))
t.Run("VerifyRelationships", integration_tests.UpdateRelationshipTest(dbAdapterURI, client))
t.Run("DeleteRelationship", integration_tests.DeleteRelationshipTest(dbAdapterURI, client))
}
}

View File

@@ -0,0 +1,23 @@
meta {
name: delete_relationship
type: http
seq: 21
}
patch {
url: http://localhost:8080/relationship/1/2
body: json
auth: inherit
}
headers {
X-User-ID: 1
}
body:json {
{
"relationship": {
"verified": true
}
}
}

View File

@@ -0,0 +1,19 @@
meta {
name: verify_relationship
type: http
seq: 20
}
patch {
url: http://localhost:8080/relationship/1/2
body: json
auth: inherit
}
body:json {
{
"relationship": {
"verified": false
}
}
}

View File

@@ -400,8 +400,6 @@ type GetRelationshipParams struct {
// UpdateRelationshipJSONBody defines parameters for UpdateRelationship.
type UpdateRelationshipJSONBody struct {
Id1 *int `json:"id1,omitempty"`
Id2 *int `json:"id2,omitempty"`
Relationship *FamilyRelationship `json:"relationship,omitempty"`
}