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

     1  package equipier
     2  
     3  import (
     4  	"fmt"
     5  	"io/ioutil"
     6  	"log"
     7  	"testing"
     8  
     9  	"github.com/benoitkugler/goACVE/logs"
    10  	rd "github.com/benoitkugler/goACVE/server/core/rawdata"
    11  	"github.com/benoitkugler/goACVE/server/documents"
    12  )
    13  
    14  var ct Controller
    15  
    16  func init() {
    17  	db, err := rd.ConnectDB(logs.DBDev)
    18  	if err != nil {
    19  		log.Fatal(err)
    20  	}
    21  	ct.DB = db
    22  }
    23  
    24  func getEquipier(t *testing.T) rd.Equipier {
    25  	row := ct.DB.QueryRow("SELECT * FROM equipiers LIMIT 1")
    26  	equipier, err := rd.ScanEquipier(row)
    27  	if err != nil {
    28  		t.Fatal("can't load one equipier", err)
    29  	}
    30  	return equipier
    31  }
    32  
    33  func TestLoad(t *testing.T) {
    34  	equipier := getEquipier(t)
    35  	datas, err := ct.loadData("localhost:8080", equipier.Id)
    36  	if err != nil {
    37  		t.Fatal(err)
    38  	}
    39  	fmt.Println(datas)
    40  }
    41  
    42  func TestUpdate(t *testing.T) {
    43  	equipier := getEquipier(t)
    44  	var eq EquipierEquipier
    45  	eq.Nom = "KUGLER"
    46  	eq.Prenom = "Benoit"
    47  	eq.Charte = rd.OBNon
    48  	eq.InvitationEquipier = rd.NonInvite
    49  	eq.Appro = rd.ACanoe
    50  
    51  	out, err := ct.updateEquipier(eq, equipier.Id)
    52  	if err != nil {
    53  		t.Fatal(err)
    54  	}
    55  	if out.InvitationEquipier != rd.Verifie {
    56  		t.Fatalf("should be verified, got %v", out.InvitationEquipier)
    57  	}
    58  	if out.Appro != "custom" {
    59  		t.Fatal()
    60  	}
    61  }
    62  
    63  func TestCreeDocument(t *testing.T) {
    64  	fileContent, err := ioutil.ReadFile("../../ressources/RIB.pdf")
    65  	if err != nil {
    66  		t.Fatal(err)
    67  	}
    68  	equipier := getEquipier(t)
    69  
    70  	row := ct.DB.QueryRow("SELECT * FROM contraintes WHERE builtin = 'bafa'")
    71  	contrainte, err := rd.ScanContrainte(row)
    72  	if err != nil {
    73  		t.Fatal(err)
    74  	}
    75  
    76  	doc, err := documents.CreeDocumentEquipier(ct.Signing, ct.DB, "localhost:8080", equipier.Id, documents.ParamsNewDocument{
    77  		IdContrainte: contrainte.Id,
    78  		Description:  "Ajouté depuis la page Equipier",
    79  		FileContent:  fileContent,
    80  		FileName:     "RIB.pdf",
    81  	})
    82  	if err != nil {
    83  		t.Fatal(err)
    84  	}
    85  	fmt.Println(doc)
    86  
    87  }
    88  
    89  func TestCharte(t *testing.T) {
    90  	equipier := getEquipier(t)
    91  
    92  	err := ct.updateCharte(equipier.Id, rd.OBOui)
    93  	if err != nil {
    94  		t.Fatal(err)
    95  	}
    96  }