mirror of
https://github.com/vcscsvcscs/GenerationsHeritage.git
synced 2025-08-13 06:19:05 +02:00
init writing first integration test
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -88,6 +91,52 @@ func TestIntegration(t *testing.T) {
|
||||
t.Log("Memgraph Running: ", memgraphC.IsRunning())
|
||||
t.Log(dbAdapterC.Logs(t.Context()))
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
dbAdapterHost, err := dbAdapterC.Host(t.Context())
|
||||
require.NoError(t, err)
|
||||
dbAdapterPort, err := dbAdapterC.MappedPort(t.Context(), "8080/tcp")
|
||||
require.NoError(t, err)
|
||||
dbAdapterURI := "http://" + dbAdapterHost + ":" + dbAdapterPort.Port()
|
||||
|
||||
testClient := &http.Client{}
|
||||
t.Run("TestCreatePersonByGoogleId", CreatePersonByGoogleIdTest(dbAdapterURI, testClient))
|
||||
}
|
||||
|
||||
func CreatePersonByGoogleIdTest(dbAdapterUri string, client *http.Client) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
url := dbAdapterUri + "/person/google/test-google-id"
|
||||
requestBody := map[string]any{
|
||||
"first_name": "John",
|
||||
"last_name": "Doe",
|
||||
"born": "1990-01-01",
|
||||
"limit": 10,
|
||||
"mothers_first_name": "Jane",
|
||||
"mothers_last_name": "Doe",
|
||||
}
|
||||
|
||||
body, err := json.Marshal(requestBody)
|
||||
require.NoError(t, err)
|
||||
|
||||
req, err := http.NewRequestWithContext(t.Context(), http.MethodPost, url, bytes.NewBuffer(body))
|
||||
require.NoError(t, err)
|
||||
req.Header.Set("Content-Type", "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
|
||||
t.Log("Response Status Code: ", responseBody)
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
|
||||
require.Equal(t, int(1), responseBody["id"])
|
||||
require.Equal(t, "John", responseBody["first_name"])
|
||||
require.Equal(t, "Doe", responseBody["last_name"])
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user