2023-11-18 11:12:07 +01:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
2023-12-21 17:38:05 +01:00
|
|
|
"git.andreafazzi.eu/andrea/probo/lib/models"
|
2023-11-18 11:12:07 +01:00
|
|
|
"github.com/remogatto/prettytest"
|
|
|
|
)
|
|
|
|
|
|
|
|
type participantTestSuite struct {
|
|
|
|
prettytest.Suite
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *participantTestSuite) TestCreate() {
|
|
|
|
store := NewStore[*models.Participant]()
|
|
|
|
|
|
|
|
p_1, err := store.Create(&models.Participant{
|
|
|
|
Lastname: "Doe",
|
|
|
|
Firstname: "John",
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Nil(err)
|
|
|
|
|
|
|
|
p_2, err := store.Create(&models.Participant{
|
|
|
|
Lastname: "Doe",
|
|
|
|
Firstname: "John",
|
|
|
|
Attributes: map[string]string{"class": "1 D LIN"},
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Nil(err)
|
|
|
|
|
|
|
|
t.False(p_1.GetHash() == p_2.GetHash())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *participantTestSuite) TestUpdate() {
|
|
|
|
store := NewStore[*models.Participant]()
|
|
|
|
|
|
|
|
p, err := store.Create(&models.Participant{
|
|
|
|
Lastname: "Doe",
|
|
|
|
Firstname: "John",
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Nil(err)
|
|
|
|
|
|
|
|
updatedP, err := store.Update(&models.Participant{
|
|
|
|
Lastname: "Doe",
|
|
|
|
Firstname: "John",
|
|
|
|
Attributes: map[string]string{"class": "1 D LIN"},
|
|
|
|
}, p.ID)
|
|
|
|
|
|
|
|
t.Nil(err)
|
|
|
|
|
|
|
|
t.False(p.GetHash() == updatedP.GetHash())
|
|
|
|
}
|
2023-12-21 17:38:05 +01:00
|
|
|
|
|
|
|
func (t *participantTestSuite) TestImportCSV() {
|
|
|
|
store := NewParticipantStore()
|
|
|
|
|
|
|
|
participants, err := store.ImportCSV("./testdata/participants.csv")
|
|
|
|
|
|
|
|
t.Nil(err)
|
|
|
|
t.Equal(3, len(participants))
|
|
|
|
t.Equal("1 D LIN", participants[0].Attributes.Get("class"))
|
|
|
|
}
|