bottin/client_test.go
Victor Lacasse-Beaudoin e847f693e0 rework: renommer champs dans entities et ajouter MembresPOST
- ajouter et tester InsertMembres
- ajouter sql/views.sql
- ajouter view `membres_for_display` -> concat names ou prefered name
- rendre plusieurs champs NOT NULL dans schema
2024-06-17 17:25:53 -04:00

82 lines
1.5 KiB
Go

package main
import (
"net/http"
"testing"
"codeberg.org/vlbeaudoin/voki/v3"
"github.com/spf13/viper"
)
func init() {
initConfig()
}
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)
}
})
//TODO create or replace schema
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)
}
})
//TODO insert membres
t.Run("insert membres",
func(t *testing.T) {
membres := []Membre{
{
ID: "0000000",
FirstName: "Test",
LastName: "User",
ProgrammeID: "404.42",
},
{
ID: "1234567",
FirstName: "Deadname",
LastName: "User",
PreferedName: "User, Test-Name",
ProgrammeID: "200.10",
},
}
_, err := apiClient.InsertMembres(membres...)
if err != nil {
t.Error(err)
}
})
//TODO get membre
//TODO update membre prefered name
//TODO get membres
}