diff --git a/api/openapi.json b/api/openapi.json index e497797..e6f3f5f 100644 --- a/api/openapi.json +++ b/api/openapi.json @@ -1117,12 +1117,6 @@ "schema": { "type": "object", "properties": { - "id1": { - "type": "integer" - }, - "id2": { - "type": "integer" - }, "relationship": { "$ref": "#/components/schemas/FamilyRelationship" } diff --git a/apps/db-adapter/integration-tests/payloads/verify_relationship.json b/apps/db-adapter/integration-tests/payloads/verify_relationship.json index 5b06846..ef8aab5 100644 --- a/apps/db-adapter/integration-tests/payloads/verify_relationship.json +++ b/apps/db-adapter/integration-tests/payloads/verify_relationship.json @@ -1,5 +1,5 @@ { "relationship": { - "verified": false + "verified": true } } \ No newline at end of file diff --git a/apps/db-adapter/integration-tests/relationship.go b/apps/db-adapter/integration-tests/relationship.go index 4c6ff6a..ada3329 100644 --- a/apps/db-adapter/integration-tests/relationship.go +++ b/apps/db-adapter/integration-tests/relationship.go @@ -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) + } } diff --git a/apps/db-adapter/internal/api/relationship.go b/apps/db-adapter/internal/api/relationship.go index ea1020d..039a284 100644 --- a/apps/db-adapter/internal/api/relationship.go +++ b/apps/db-adapter/internal/api/relationship.go @@ -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 diff --git a/apps/db-adapter/internal/memgraph/queries/delete_relationship.cypher b/apps/db-adapter/internal/memgraph/queries/delete_relationship.cypher index f60b83d..11de22d 100644 --- a/apps/db-adapter/internal/memgraph/queries/delete_relationship.cypher +++ b/apps/db-adapter/internal/memgraph/queries/delete_relationship.cypher @@ -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; \ No newline at end of file diff --git a/apps/db-adapter/internal/memgraph/queries/update_relationship.cypher b/apps/db-adapter/internal/memgraph/queries/update_relationship.cypher index 3d777d1..bf98db4 100644 --- a/apps/db-adapter/internal/memgraph/queries/update_relationship.cypher +++ b/apps/db-adapter/internal/memgraph/queries/update_relationship.cypher @@ -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 diff --git a/apps/db-adapter/main_test.go b/apps/db-adapter/main_test.go index c55a233..6b57173 100644 --- a/apps/db-adapter/main_test.go +++ b/apps/db-adapter/main_test.go @@ -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)) } } diff --git a/apps/db-adapter/manual-testing/delete_relationship.bru b/apps/db-adapter/manual-testing/delete_relationship.bru new file mode 100644 index 0000000..a0a7286 --- /dev/null +++ b/apps/db-adapter/manual-testing/delete_relationship.bru @@ -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 + } + } +} diff --git a/apps/db-adapter/manual-testing/verify_relationship.bru b/apps/db-adapter/manual-testing/verify_relationship.bru new file mode 100644 index 0000000..ced3a2d --- /dev/null +++ b/apps/db-adapter/manual-testing/verify_relationship.bru @@ -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 + } + } +} diff --git a/apps/db-adapter/pkg/api/api.gen.go b/apps/db-adapter/pkg/api/api.gen.go index 5a72e43..234dd12 100644 --- a/apps/db-adapter/pkg/api/api.gen.go +++ b/apps/db-adapter/pkg/api/api.gen.go @@ -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"` }