participant_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package store
  2. import (
  3. "git.andreafazzi.eu/andrea/probo/pkg/models"
  4. "github.com/remogatto/prettytest"
  5. )
  6. type participantTestSuite struct {
  7. prettytest.Suite
  8. }
  9. func (t *participantTestSuite) TestCreate() {
  10. store := NewStore[*models.Participant]()
  11. p_1, err := store.Create(&models.Participant{
  12. Lastname: "Doe",
  13. Firstname: "John",
  14. })
  15. t.Nil(err)
  16. p_2, err := store.Create(&models.Participant{
  17. Lastname: "Doe",
  18. Firstname: "John",
  19. Attributes: map[string]string{"class": "1 D LIN"},
  20. })
  21. t.Nil(err)
  22. t.False(p_1.GetHash() == p_2.GetHash())
  23. }
  24. func (t *participantTestSuite) TestUpdate() {
  25. store := NewStore[*models.Participant]()
  26. p, err := store.Create(&models.Participant{
  27. Lastname: "Doe",
  28. Firstname: "John",
  29. })
  30. t.Nil(err)
  31. updatedP, err := store.Update(&models.Participant{
  32. Lastname: "Doe",
  33. Firstname: "John",
  34. Attributes: map[string]string{"class": "1 D LIN"},
  35. }, p.ID)
  36. t.Nil(err)
  37. t.False(p.GetHash() == updatedP.GetHash())
  38. }
  39. func (t *participantTestSuite) TestImportCSV() {
  40. store := NewParticipantStore()
  41. participants, err := store.ImportCSV("./testdata/participants.csv")
  42. t.Nil(err)
  43. t.Equal(3, len(participants))
  44. t.Equal("1 D LIN", participants[0].Attributes.Get("class"))
  45. t.Equal(6, len(participants[0].Token))
  46. }