mirror of
https://github.com/vcscsvcscs/GenerationsHeritage.git
synced 2025-08-14 06:49:05 +02:00
implement integration tests for person operations
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"first_name": "Jhon",
|
||||
"last_name": "Doe",
|
||||
"born": "1985-07-01",
|
||||
"limit": 1000,
|
||||
"mothers_first_name": "Mary",
|
||||
"mothers_last_name": "Smith",
|
||||
"email": "jd@example.com"
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"invite_code": "test-invite-code"
|
||||
}
|
150
apps/db-adapter/integration-tests/payloads/update_person.json
Normal file
150
apps/db-adapter/integration-tests/payloads/update_person.json
Normal file
@@ -0,0 +1,150 @@
|
||||
{
|
||||
"invite_code": "ABCD1234",
|
||||
"first_name": "John",
|
||||
"middle_name": "Fitzgerald",
|
||||
"last_name": "Doe",
|
||||
"titles": [
|
||||
"Dr.",
|
||||
"Prof."
|
||||
],
|
||||
"suffixes": [
|
||||
"Jr."
|
||||
],
|
||||
"extra_names": [
|
||||
"Johnny",
|
||||
"J.D."
|
||||
],
|
||||
"aliases": [
|
||||
"The Professor"
|
||||
],
|
||||
"mothers_first_name": "Jane",
|
||||
"mothers_last_name": "Smith",
|
||||
"born": "1980-05-15",
|
||||
"place_of_birth": "New York, USA",
|
||||
"died": null,
|
||||
"place_of_death": null,
|
||||
"life_events": [
|
||||
{
|
||||
"from": "2000-01-01",
|
||||
"to": "2004-12-31",
|
||||
"description": "Studied at Harvard University"
|
||||
},
|
||||
{
|
||||
"from": "2005-01-01",
|
||||
"to": "2015-01-01",
|
||||
"description": "Worked at NASA"
|
||||
}
|
||||
],
|
||||
"occupations": [
|
||||
"Engineer",
|
||||
"Professor"
|
||||
],
|
||||
"occupation_to_display": "Professor",
|
||||
"others_said": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Alice Johnson",
|
||||
"relationship": "Colleague",
|
||||
"description": "John was always a dedicated professional.",
|
||||
"url": "https://example.com/testimonial"
|
||||
}
|
||||
],
|
||||
"limit": 10,
|
||||
"photos": [
|
||||
{
|
||||
"url": "https://example.com/photo1.jpg",
|
||||
"description": "Graduation day",
|
||||
"date": "2004-06-15",
|
||||
"name": "Harvard Graduation"
|
||||
}
|
||||
],
|
||||
"videos": [
|
||||
{
|
||||
"url": "https://example.com/video1.mp4",
|
||||
"description": "Interview about Mars mission",
|
||||
"date": "2012-09-10",
|
||||
"name": "NASA Interview"
|
||||
}
|
||||
],
|
||||
"audios": [
|
||||
{
|
||||
"url": "https://example.com/audio1.mp3",
|
||||
"description": "Podcast guest appearance",
|
||||
"date": "2020-11-20",
|
||||
"name": "Science Today Podcast"
|
||||
}
|
||||
],
|
||||
"profile_picture": "https://example.com/profile.jpg",
|
||||
"verified": true,
|
||||
"email": "john.doe@example.com",
|
||||
"phone": "+1-555-123-4567",
|
||||
"residence": {
|
||||
"city": "San Francisco",
|
||||
"country": "USA",
|
||||
"zip_code": "94103",
|
||||
"address_line_1": "123 Main St",
|
||||
"address_line_2": "Apt 4B"
|
||||
},
|
||||
"religion": "Agnostic",
|
||||
"baptized": null,
|
||||
"ideologies": [
|
||||
"Environmentalism",
|
||||
"Humanism"
|
||||
],
|
||||
"blood_type": "O+",
|
||||
"allergies": [
|
||||
"Peanuts",
|
||||
"Pollen"
|
||||
],
|
||||
"medications": [
|
||||
{
|
||||
"name": "Ibuprofen",
|
||||
"description": "Pain relief",
|
||||
"components": "Ibuprofen 400mg",
|
||||
"dosage": "Once a day",
|
||||
"from": "2024-01-01",
|
||||
"to": null
|
||||
}
|
||||
],
|
||||
"medical_conditions": [
|
||||
{
|
||||
"condition": "Hypertension",
|
||||
"diagnosed_on": "2023-03-01"
|
||||
}
|
||||
],
|
||||
"height": 180.5,
|
||||
"weight": 75.0,
|
||||
"hair_colour": "Brown",
|
||||
"skin_colour": "Light",
|
||||
"eye_colour": "Green",
|
||||
"sports": [
|
||||
"Tennis",
|
||||
"Cycling"
|
||||
],
|
||||
"hobbies": [
|
||||
"Painting",
|
||||
"Chess"
|
||||
],
|
||||
"interests": [
|
||||
"Astronomy",
|
||||
"AI Research"
|
||||
],
|
||||
"languages": [
|
||||
{
|
||||
"language": "English",
|
||||
"level": "Native"
|
||||
},
|
||||
{
|
||||
"language": "French",
|
||||
"level": "Intermediate"
|
||||
}
|
||||
],
|
||||
"notes": [
|
||||
{
|
||||
"date": "2023-12-01",
|
||||
"title": "Family Tree Interview",
|
||||
"note": "Discussed with John's aunt about his early years.",
|
||||
"url": "https://example.com/note1"
|
||||
}
|
||||
]
|
||||
}
|
@@ -1,16 +1,187 @@
|
||||
package integration_tests
|
||||
|
||||
func CreatePerson() {
|
||||
import (
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/vcscsvcscs/GenerationsHeritage/apps/db-adapter/pkg/api"
|
||||
)
|
||||
|
||||
//go:embed payloads\create_other_person.json
|
||||
var create_other_person []byte
|
||||
|
||||
func CreatePersonTest(dbAdapterUri string, client *http.Client) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
url := dbAdapterUri + "/person"
|
||||
|
||||
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)
|
||||
|
||||
require.Equal(t, "Jhon", responseBody["Props"].(map[string]any)["first_name"])
|
||||
require.Equal(t, "Doe", responseBody["Props"].(map[string]any)["last_name"])
|
||||
}
|
||||
}
|
||||
|
||||
func GetPersonById() {
|
||||
func GetPersonById(dbAdapterUri string, client *http.Client) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
url := dbAdapterUri + "/person/0"
|
||||
|
||||
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", "0")
|
||||
|
||||
// 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)
|
||||
|
||||
require.Equal(t, "Alice", responseBody["Props"].(map[string]any)["first_name"])
|
||||
require.Equal(t, "Wonderland", responseBody["Props"].(map[string]any)["last_name"])
|
||||
}
|
||||
}
|
||||
|
||||
func SoftDeletePerson() {
|
||||
func SoftDeletePersonTest(dbAdapterUri string, client *http.Client) func(t *testing.T) { //nolint:dupl,lll // This just does not worth abstracting anymore
|
||||
return func(t *testing.T) {
|
||||
url := dbAdapterUri + "/person/0"
|
||||
|
||||
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", "0")
|
||||
|
||||
// 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)
|
||||
|
||||
require.Equal(t, "Person soft deleted", responseBody["description"])
|
||||
}
|
||||
}
|
||||
|
||||
func UpdatePerson() {
|
||||
//go:embed payloads\update_person.json
|
||||
var update_person []byte
|
||||
|
||||
func UpdatePersonTest(dbAdapterUri string, client *http.Client) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
url := dbAdapterUri + "/person/1"
|
||||
|
||||
req, err := http.NewRequestWithContext(t.Context(), http.MethodPatch, url, bytes.NewBuffer(update_person))
|
||||
require.NoError(t, err)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("X-User-ID", "1")
|
||||
|
||||
// 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)
|
||||
|
||||
require.Equal(t, "John", responseBody["Props"].(map[string]any)["first_name"])
|
||||
require.Equal(t, "Doe", responseBody["Props"].(map[string]any)["last_name"])
|
||||
require.Equal(t, "ABCD1234", responseBody["Props"].(map[string]any)["invite_code"])
|
||||
}
|
||||
}
|
||||
|
||||
func HardDeletePerson() {
|
||||
//go:embed payloads\generate_invite_code.json
|
||||
var generate_invite_code []byte
|
||||
|
||||
func UpdatePersonWithInviteCodeTest(dbAdapterUri string, client *http.Client) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
url := dbAdapterUri + "/person/1"
|
||||
|
||||
req, err := http.NewRequestWithContext(t.Context(), http.MethodPatch, url, bytes.NewBuffer(generate_invite_code))
|
||||
require.NoError(t, err)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("X-User-ID", "0")
|
||||
|
||||
// Send the request
|
||||
resp, err := client.Do(req)
|
||||
require.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
|
||||
var responseBody api.Person
|
||||
err = json.NewDecoder(resp.Body).Decode(&responseBody)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Validate the response
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
|
||||
require.NotNil(t, responseBody.Id)
|
||||
|
||||
require.Equal(t, "test-invite-code", *responseBody.Props.InviteCode)
|
||||
}
|
||||
}
|
||||
|
||||
func HardDeletePersonTest(dbAdapterUri string, client *http.Client) func(t *testing.T) { //nolint:dupl,lll // This just does not worth abstracting anymore
|
||||
return func(t *testing.T) {
|
||||
url := dbAdapterUri + "/person/0/hard-delete"
|
||||
|
||||
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", "0")
|
||||
|
||||
// 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)
|
||||
|
||||
require.Equal(t, "Person hard deleted", responseBody["description"])
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user