mirror of
https://github.com/vcscsvcscs/GenerationsHeritage.git
synced 2025-08-13 06:19:05 +02:00
implement integration test for relationship update and delete
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"relationship": {
|
||||
"verified": false
|
||||
"verified": true
|
||||
}
|
||||
}
|
@@ -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)
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
@@ -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
|
||||
|
@@ -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))
|
||||
}
|
||||
}
|
||||
|
23
apps/db-adapter/manual-testing/delete_relationship.bru
Normal file
23
apps/db-adapter/manual-testing/delete_relationship.bru
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
19
apps/db-adapter/manual-testing/verify_relationship.bru
Normal file
19
apps/db-adapter/manual-testing/verify_relationship.bru
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
@@ -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"`
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user