probo/pkg/store/participant_test.go

63 rivejä
1,2 KiB
Go

package store
import (
"git.andreafazzi.eu/andrea/probo/pkg/models"
"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())
}
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"))
t.Equal(6, len(participants[0].Token))
}