2024-06-11 17:28:20 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"codeberg.org/vlbeaudoin/voki/v3"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
2024-06-17 14:07:49 -04:00
|
|
|
func init() {
|
|
|
|
initConfig()
|
|
|
|
}
|
|
|
|
|
2024-06-11 17:28:20 -04:00
|
|
|
func TestAPI(t *testing.T) {
|
|
|
|
var cfg Config
|
|
|
|
if err := viper.Unmarshal(&cfg); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
httpClient := http.DefaultClient
|
|
|
|
defer httpClient.CloseIdleConnections()
|
|
|
|
|
|
|
|
vokiClient := voki.New(httpClient, "localhost", cfg.API.Key, cfg.API.Port, "http")
|
|
|
|
apiClient := APIClient{vokiClient}
|
|
|
|
|
|
|
|
t.Run("get API health", func(t *testing.T) {
|
|
|
|
health, err := apiClient.GetHealth()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
want := "ok"
|
|
|
|
got := health
|
|
|
|
|
|
|
|
if want != got {
|
|
|
|
t.Errorf("want=%s got=%s", want, got)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-06-17 14:07:49 -04:00
|
|
|
//TODO create or replace schema
|
2024-06-18 19:44:20 -04:00
|
|
|
|
2024-06-17 14:07:49 -04:00
|
|
|
t.Run("insert programmes",
|
|
|
|
func(t *testing.T) {
|
|
|
|
programmes := []Programme{
|
|
|
|
{"404.42", "Cool programme"},
|
|
|
|
{"200.10", "Autre programme"},
|
|
|
|
}
|
|
|
|
t.Log("programmes:", programmes)
|
|
|
|
_, err := apiClient.InsertProgrammes(programmes...)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
})
|
2024-06-18 19:44:20 -04:00
|
|
|
|
|
|
|
testMembres := []Membre{
|
|
|
|
{
|
|
|
|
ID: "0000000",
|
|
|
|
FirstName: "Test",
|
|
|
|
LastName: "User",
|
|
|
|
ProgrammeID: "404.42",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "1234567",
|
|
|
|
FirstName: "Deadname",
|
|
|
|
LastName: "User",
|
|
|
|
PreferedName: "User, Test-Name",
|
|
|
|
ProgrammeID: "200.10",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-06-17 17:25:53 -04:00
|
|
|
t.Run("insert membres",
|
|
|
|
func(t *testing.T) {
|
2024-06-18 19:44:20 -04:00
|
|
|
_, err := apiClient.InsertMembres(testMembres...)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2024-06-17 17:25:53 -04:00
|
|
|
}
|
2024-06-18 19:44:20 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("get membre",
|
|
|
|
func(t *testing.T) {
|
|
|
|
membre, err := apiClient.GetMembre(testMembres[0].ID)
|
2024-06-17 17:25:53 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2024-06-18 19:44:20 -04:00
|
|
|
|
|
|
|
want := testMembres[0].LastName
|
|
|
|
got := membre.LastName
|
|
|
|
|
|
|
|
if want != got {
|
|
|
|
t.Errorf("want=%s got=%s", want, got)
|
|
|
|
}
|
2024-06-17 17:25:53 -04:00
|
|
|
})
|
2024-06-18 19:44:20 -04:00
|
|
|
|
|
|
|
t.Run("get invalid membre",
|
|
|
|
func(t *testing.T) {
|
|
|
|
_, err := apiClient.GetMembre("invalid")
|
|
|
|
if err == nil {
|
|
|
|
t.Error("`invalid` should not have been accepted as value to GetMembre, but did")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-06-17 14:07:49 -04:00
|
|
|
//TODO update membre prefered name
|
2024-06-18 19:44:20 -04:00
|
|
|
/*
|
|
|
|
t.Run("",
|
|
|
|
func(t *testing.T) {
|
|
|
|
if err := apiClient.UpdateMembrePreferedName(testMembres[0].ID, "User, Galaxy"); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
*/
|
2024-06-17 14:07:49 -04:00
|
|
|
//TODO get membres
|
2024-06-18 21:21:30 -04:00
|
|
|
t.Run("get membres, max 50",
|
|
|
|
func(t *testing.T) {
|
|
|
|
membres, err := apiClient.GetMembres(50)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
t.Log(membres)
|
|
|
|
})
|
|
|
|
|
|
|
|
//TODO remove test membres and programmes
|
2024-06-11 17:28:20 -04:00
|
|
|
}
|