mirror of
https://github.com/vcscsvcscs/GenerationsHeritage.git
synced 2025-08-14 06:49:05 +02:00
add person and relationship tests
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"person": {
|
||||
"first_name": "Johannes",
|
||||
"last_name": "Doe",
|
||||
"born": "2000-07-01",
|
||||
"limit": 1000,
|
||||
"mothers_first_name": "Frances",
|
||||
"mothers_last_name": "Soft",
|
||||
"email": "dj@example.com"
|
||||
},
|
||||
"type": "child",
|
||||
"relationship": {
|
||||
"verified": true,
|
||||
"notes": "Test notes",
|
||||
"from": "2023-01-01"
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"person": {
|
||||
"first_name": "Ferdinand",
|
||||
"last_name": "Fritz",
|
||||
"born": "1940-06-01",
|
||||
"limit": 1000,
|
||||
"mothers_first_name": "Feras",
|
||||
"mothers_last_name": "Frea",
|
||||
"email": "FFd@example.com"
|
||||
},
|
||||
"type": "parent",
|
||||
"relationship": {
|
||||
"verified": true
|
||||
}
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"person": {
|
||||
"first_name": "Sandra",
|
||||
"last_name": "Doe",
|
||||
"born": "1987-07-01",
|
||||
"limit": 1000,
|
||||
"mothers_first_name": "Mary",
|
||||
"mothers_last_name": "Smith",
|
||||
"email": "SD@example.com"
|
||||
},
|
||||
"type": "sibling",
|
||||
"relationship": {
|
||||
"verified": true,
|
||||
"notes": "Good siblings"
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"person": {
|
||||
"first_name": "Ferdinand",
|
||||
"last_name": "Fritz",
|
||||
"born": "1970-04-01",
|
||||
"limit": 1000,
|
||||
"mothers_first_name": "Seabruch",
|
||||
"mothers_last_name": "Klein",
|
||||
"email": "FF@example.com"
|
||||
},
|
||||
"type": "spouse",
|
||||
"relationship": {
|
||||
"verified": true
|
||||
}
|
||||
}
|
@@ -1,4 +1,63 @@
|
||||
package integration_tests
|
||||
|
||||
func CreatePersonAndRelationship() {
|
||||
import (
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
//go:embed payloads/create_person_and_relationship_child.json
|
||||
var create_child []byte
|
||||
|
||||
//go:embed payloads/create_person_and_relationship_parent.json
|
||||
var create_parent []byte
|
||||
|
||||
//go:embed payloads/create_person_and_relationship_spouse.json
|
||||
var create_spouse []byte
|
||||
|
||||
//go:embed payloads/create_person_and_relationship_sibling.json
|
||||
var create_sibling []byte
|
||||
|
||||
func CreateAFamilyTest(dbAdapterUri string, client *http.Client) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
t.Run("CreateChild", CreatePersonAndRelationshipTest(dbAdapterUri, &create_child, client))
|
||||
t.Run("CreateParent", CreatePersonAndRelationshipTest(dbAdapterUri, &create_parent, client))
|
||||
t.Run("CreateSpouse", CreatePersonAndRelationshipTest(dbAdapterUri, &create_spouse, client))
|
||||
t.Run("CreateSibling", CreatePersonAndRelationshipTest(dbAdapterUri, &create_sibling, client))
|
||||
}
|
||||
}
|
||||
|
||||
func CreatePersonAndRelationshipTest(dbAdapterUri string, payload *[]byte, client *http.Client) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
url := dbAdapterUri + "/person_and_relationship/1"
|
||||
|
||||
req, err := http.NewRequestWithContext(t.Context(), http.MethodPost, url, bytes.NewBuffer(create_other_person))
|
||||
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)
|
||||
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["Id"]
|
||||
require.True(t, ok)
|
||||
_, ok = responseBody["person"]
|
||||
require.True(t, ok)
|
||||
_, ok = responseBody["relationship"]
|
||||
require.True(t, ok)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user