49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
package mappers
|
|
|
|
import (
|
|
"code.dlmw.ch/dlmw/qv/internal/models"
|
|
uuid2 "github.com/google/uuid"
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestElectionResponse(t *testing.T) {
|
|
layout := "2006-01-02 15:04:05 -0700"
|
|
parsedCreatedAtTime, err := time.Parse(layout, "2025-01-14 15:13:37 +0000")
|
|
if err != nil {
|
|
t.Fatal(err.Error())
|
|
}
|
|
|
|
parsedExpiresAtTime, err := time.Parse(layout, "2025-01-15 15:13:37 +0000")
|
|
if err != nil {
|
|
t.Fatal(err.Error())
|
|
}
|
|
|
|
uuid, _ := uuid2.NewV7()
|
|
election := models.Election{
|
|
ID: uuid.String(),
|
|
Name: "The best",
|
|
Tokens: 100,
|
|
AreVotersKnown: true,
|
|
MaxVoters: 150,
|
|
CreatedAt: parsedCreatedAtTime.In(time.UTC),
|
|
ExpiresAt: parsedExpiresAtTime.In(time.UTC),
|
|
Choices: []string{"You", "Me"},
|
|
}
|
|
|
|
response := ElectionResponse(&election)
|
|
|
|
assert.Equal(t, uuid.String(), response.Id)
|
|
assert.Equal(t, "The best", response.Name)
|
|
assert.Equal(t, 100, response.Tokens)
|
|
assert.Equal(t, true, response.AreVotersKnown)
|
|
assert.Equal(t, 150, response.MaxVoters)
|
|
assert.Equal(t, "2025-01-14 15:13:37 +0000 UTC", response.CreatedAt)
|
|
assert.Equal(t, "2025-01-15 15:13:37 +0000 UTC", response.ExpiresAt)
|
|
|
|
for _, choice := range election.Choices {
|
|
assert.Contains(t, election.Choices, choice)
|
|
}
|
|
}
|