github.com/benoitkugler/goacve@v0.0.0-20201217100549-151ce6e55dc8/server/vote/rapport_test.go (about)

     1  package vote
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"testing"
     7  	"time"
     8  
     9  	"github.com/benoitkugler/goACVE/server/core/utils/pdf"
    10  )
    11  
    12  func TestBilans(t *testing.T) {
    13  	pdf.IMAGES_PATH = "../../ressources/images"
    14  
    15  	candidats := []Candidat{
    16  		randCandidat(),
    17  		randCandidat(),
    18  		randCandidat(),
    19  		randCandidat(),
    20  		randCandidat(),
    21  		randCandidat(),
    22  		randCandidat(),
    23  		randCandidat(),
    24  		randCandidat(),
    25  		randCandidat(),
    26  		randCandidat(),
    27  		randCandidat(),
    28  	}
    29  	voix := map[int64]int{}
    30  	for i, cd := range candidats {
    31  		voix[cd.Id] = i + 100
    32  		candidats[i].Label = cd.Label
    33  	}
    34  	votes := []voteParticipants{
    35  		{VoteAdmin: VoteAdmin{VoteCandidats: VoteCandidats{Vote: randVote(), Candidats: candidats}, Voix: voix}, nbParticipants: 15, nbTotal: 170},
    36  		{VoteAdmin: VoteAdmin{VoteCandidats: VoteCandidats{Vote: randVote(), Candidats: candidats}, Voix: voix}, nbParticipants: 15, nbTotal: 170},
    37  		{VoteAdmin: VoteAdmin{VoteCandidats: VoteCandidats{Vote: randVote(), Candidats: candidats}, Voix: voix}, nbParticipants: 15, nbTotal: 170},
    38  		{VoteAdmin: VoteAdmin{VoteCandidats: VoteCandidats{Vote: randVote(), Candidats: candidats}, Voix: voix}, nbParticipants: 15, nbTotal: 170},
    39  		{VoteAdmin: VoteAdmin{VoteCandidats: VoteCandidats{Vote: randVote(), Candidats: candidats}, Voix: voix}, nbParticipants: 15, nbTotal: 170},
    40  	}
    41  	b, err := genereBilanVotes(votes)
    42  	if err != nil {
    43  		t.Fatal(err)
    44  	}
    45  	err = ioutil.WriteFile("bilan_test.pdf", b, os.ModePerm)
    46  	if err != nil {
    47  		t.Fatal(err)
    48  	}
    49  }
    50  
    51  func TestBilanPersonne(t *testing.T) {
    52  	pdf.IMAGES_PATH = "../../ressources/images"
    53  
    54  	candidats := []Candidat{
    55  		randCandidat(),
    56  		randCandidat(),
    57  		randCandidat(),
    58  		randCandidat(),
    59  		randCandidat(),
    60  		randCandidat(),
    61  		randCandidat(),
    62  		randCandidat(),
    63  		randCandidat(),
    64  		randCandidat(),
    65  		randCandidat(),
    66  		randCandidat(),
    67  	}
    68  	ids := Ids{}
    69  	for _, cd := range candidats {
    70  		ids = append(ids, cd.Id)
    71  	}
    72  	votes := []VotePersonneComplet{
    73  		{VoteCandidats: VoteCandidats{Vote: randVote(), Candidats: candidats}, Time: time.Now(), Choix: ids[0:3]},
    74  		{VoteCandidats: VoteCandidats{Vote: randVote(), Candidats: candidats}, Time: time.Now(), Choix: ids[2:8]},
    75  		{VoteCandidats: VoteCandidats{Vote: randVote(), Candidats: candidats}, Time: time.Now(), Choix: ids[1:4]},
    76  		{VoteCandidats: VoteCandidats{Vote: randVote(), Candidats: candidats}, Time: time.Now(), Choix: ids},
    77  		{VoteCandidats: VoteCandidats{Vote: randVote(), Candidats: candidats}, Time: time.Now(), Choix: ids[0:1]},
    78  	}
    79  	b, err := genereBilanPersonne(MetaPersonne{PrenomNom: "Benoit KUGLER"}, votes)
    80  	if err != nil {
    81  		t.Fatal(err)
    82  	}
    83  	err = ioutil.WriteFile("bilan_personne_test.pdf", b, os.ModePerm)
    84  	if err != nil {
    85  		t.Fatal(err)
    86  	}
    87  }