github.com/benoitkugler/goacve@v0.0.0-20201217100549-151ce6e55dc8/server/core/datamodel/acces_test.go (about) 1 package datamodel 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "testing" 7 "time" 8 9 rd "github.com/benoitkugler/goACVE/server/core/rawdata" 10 ) 11 12 func TestApercuFacture(t *testing.T) { 13 b := BaseLocale{ 14 Aides: rd.Aides{ 15 1: {Valide: false, Valeur: 45, IdParticipant: 1}, 16 2: {Valide: true, Valeur: 28, IdParticipant: 1}, 17 }, 18 Participants: rd.Participants{ 19 1: {IdPersonne: 1, IdFacture: rd.NewOptionnalId(1)}, 20 }, 21 Personnes: rd.Personnes{ 22 1: {BasePersonne: rd.BasePersonne{Nom: "KUGLER", Prenom: "Benoit"}}, 23 }, 24 Factures: rd.Factures{ 25 1: {}, 26 }, 27 } 28 ac := b.NewFacture(1) 29 fmt.Println(ac.Description()) 30 } 31 32 func TestFactureHtml(t *testing.T) { 33 base := GetLocalDBDev() 34 var fac AccesFacture 35 for id := range base.Factures { 36 fac = base.NewFacture(id) 37 break 38 } 39 err := ioutil.WriteFile("local/facture.html", []byte(fac.Description()), 0666) 40 if err != nil { 41 t.Error(err) 42 } 43 } 44 45 func TestEtatFinancier(t *testing.T) { 46 base := GetLocalDBDev() 47 fac := base.NewFacture(5882) 48 49 // on compare sans le cache ... 50 ti := time.Now() 51 fac.EtatFinancier(CacheEtatFinancier{}, false) 52 fmt.Println("etat financier sans cache :", time.Since(ti)) 53 54 cache := base.NewCacheEtatFinancier() 55 fmt.Println("mise en cache (nb) :", len(cache.FPaiements)) 56 fmt.Println("mise en cache (nb) :", len(cache.FParticipants)) 57 fmt.Println("mise en cache (nb) :", len(cache.PAides)) 58 59 // ... et avec le cache 60 ti = time.Now() 61 fac.EtatFinancier(cache, true) 62 fmt.Println("etat financier avec cache :", time.Since(ti)) 63 } 64 65 func TestFloat(t *testing.T) { 66 f1, f2 := 110., 110+1e-13 67 fmt.Println(f1 == f2) 68 } 69 70 func TestTime(t *testing.T) { 71 a := time.Now() 72 fmt.Println(a.After(a)) 73 } 74 75 func TestDuree(t *testing.T) { 76 deb := rd.Date(time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC)) 77 fin := rd.Date(time.Date(2000, 2, 6, 0, 0, 0, 0, time.UTC)) 78 fmt.Println(rd.Plage{To: deb, From: fin}.NbJours()) 79 } 80 81 func TestPrixCamp(t *testing.T) { 82 db := GetLocalDBDev() 83 ac := db.NewFacture(db.RechercheRapideFactures("garz sev")[0].Id.Int64()) 84 fmt.Println(ac.RawData().UrlEspacePerso("http://slmdk")) 85 fmt.Println(ac.RawData().Key) 86 fmt.Println(ac.Description()) 87 } 88 89 func TestDocs(t *testing.T) { 90 db := GetBase(true) 91 ac := db.NewCamp(24) 92 fmt.Println(ac.RawData().Label()) 93 fmt.Println(ac.GetRegisteredDocuments(true, true)) 94 fmt.Println(ac.RawData().Envois) 95 fmt.Println(db.Documents) 96 } 97 98 func TestListes(t *testing.T) { 99 db := GetLocalDBDev() 100 ac := db.NewCamp(22) 101 rawCamp := ac.RawData() 102 rawCamp.InscriptionSimple = true 103 db.Camps[rawCamp.Id] = rawCamp 104 ac.GetListes(true, rd.BAller, false, false) 105 106 rawCamp.InscriptionSimple = false 107 db.Camps[rawCamp.Id] = rawCamp 108 ac.GetListes(true, rd.BAller, true, false) 109 }