Skip to content
Snippets Groups Projects
Commit 1df7f023 authored by Rémi PAILHAREY's avatar Rémi PAILHAREY :fork_knife_plate:
Browse files

Merge branch '14-le-titre-par-defaut-de-la-lettre-mensuelle-est-errone' into 'dev'

Resolve "Le titre par défaut de la lettre mensuelle est erroné"

See merge request !62
parents 9451e69a 0676b63f
Branches
No related tags found
3 merge requests!73Deploy Openshift v2,!65MEP: removed Meilisearch,!62Resolve "Le titre par défaut de la lettre mensuelle est erroné"
Pipeline #54238 passed
......@@ -87,7 +87,7 @@ func (dh *DataHandler) getMonthlyReport(year int, month int) (monthlyReport Mont
err = dh.sqlClient.Where("year = ? AND month = ?", year, month).First(&mailSubject).Error
if err != nil || mailSubject.Subject == "" {
// Build default object
mailSubject.Subject = fmt.Sprintf("[Ecolyo] Votre bilan %s %v", getMonthNameWithPrep(month-1), year)
mailSubject.Subject = fmt.Sprintf("[Ecolyo] Votre bilan %s", getDateWithPrep(month-1, year))
}
var monthlyNews MonthlyNews
......@@ -111,7 +111,7 @@ func (dh *DataHandler) getMonthlyReport(year int, month int) (monthlyReport Mont
return monthlyReport, nil
}
func getMonthNameWithPrep(month int) string {
func getDateWithPrep(month int, year int) string {
frenchMonths := []string{
"de janvier",
"de février",
......@@ -126,5 +126,14 @@ func getMonthNameWithPrep(month int) string {
"de novembre",
"de décembre",
}
return frenchMonths[month]
var prevMonth = month - 1
var prevYear = year
// If month is January return December of the previous year
if month == 0 {
prevMonth = 11
prevYear = year - 1
}
return fmt.Sprintf("%s %d", frenchMonths[prevMonth], prevYear)
}
......@@ -123,7 +123,7 @@ func unloggedTests(t *testing.T) {
// Try to get a monthlyReport (must fail because no parameters are given)
do("GET", "/api/common/monthlyReport", noH, "", http.StatusBadRequest, "")
// Try to get a monthlyReport (must pass empty)
do("GET", "/api/common/monthlyReport?year=2021&month=12", noH, "", http.StatusOK, `{"year":2021,"month":12,"subject":"[Ecolyo] Votre bilan de décembre 2021","info":"","image":"","newsTitle":"","newsContent":"","question":"","link":""}`)
do("GET", "/api/common/monthlyReport?year=2021&month=12", noH, "", http.StatusOK, `{"year":2021,"month":12,"subject":"[Ecolyo] Votre bilan de novembre 2021","info":"","image":"","newsTitle":"","newsContent":"","question":"","link":""}`)
// Try to get partnersInfo (must pass)
do("GET", "/api/common/partnersInfo", noH, "", http.StatusOK, `{"ID":1,"grdf_failure":false,"enedis_failure":false,"egl_failure":false,"notification_activated":false}`)
}
......@@ -156,7 +156,7 @@ func adminTests(t *testing.T) {
// Try to get the monthlyNews created (must pass)
do("GET", "/api/admin/monthlyNews/2021/1", xsrfHeader, "", http.StatusOK, `{"year":2021,"month":1,"title":"Les nouveautés du service","content":"Nouvelles fonctionnalités"`)
// Try to get the monthlyReport (must pass)
do("GET", "/api/common/monthlyReport/2021/1", noH, "", http.StatusOK, `{"year":2021,"month":1,"subject":"[Ecolyo] Votre bilan de janvier 2021","info":"","image":"","newsTitle":"Les nouveautés du service","newsContent":"Nouvelles fonctionnalités","question":"","link":""}`)
do("GET", "/api/common/monthlyReport/2021/1", noH, "", http.StatusOK, `{"year":2021,"month":1,"subject":"[Ecolyo] Votre bilan de décembre 2020","info":"","image":"","newsTitle":"Les nouveautés du service","newsContent":"Nouvelles fonctionnalités","question":"","link":""}`)
// Try to create a poll without the XSRF-TOKEN (must fail)
do("PUT", "/api/admin/poll", noH, newPollStr, http.StatusUnauthorized, "XSRF protection triggered")
......@@ -171,7 +171,7 @@ func adminTests(t *testing.T) {
// Try to get the poll created (must pass)
do("GET", "/api/admin/poll/2021/1", xsrfHeader, "", http.StatusOK, newPollStr)
// Try to get the monthlyReport (must pass)
do("GET", "/api/common/monthlyReport/2021/1", noH, "", http.StatusOK, `{"year":2021,"month":1,"subject":"[Ecolyo] Votre bilan de janvier 2021","info":"","image":"","newsTitle":"Les nouveautés du service","newsContent":"Nouvelles fonctionnalités","question":"pollQuestion","link":"pollLink"}`)
do("GET", "/api/common/monthlyReport/2021/1", noH, "", http.StatusOK, `{"year":2021,"month":1,"subject":"[Ecolyo] Votre bilan de décembre 2020","info":"","image":"","newsTitle":"Les nouveautés du service","newsContent":"Nouvelles fonctionnalités","question":"pollQuestion","link":"pollLink"}`)
// Try to create a monthlyInfo without the XSRF-TOKEN (must fail)
do("PUT", "/api/admin/monthlyInfo", noH, monthlyInfoStr, http.StatusUnauthorized, "XSRF protection triggered")
......@@ -186,7 +186,7 @@ func adminTests(t *testing.T) {
// Try to get the monthlyInfo created (must pass)
do("GET", "/api/admin/monthlyInfo/2021/1", xsrfHeader, "", http.StatusOK, monthlyInfoStr)
// Try to get the monthlyReport (must pass)
do("GET", "/api/common/monthlyReport/2021/1", noH, "", http.StatusOK, `{"year":2021,"month":1,"subject":"[Ecolyo] Votre bilan de janvier 2021","info":"Informations du mois","image":"imagebase64","newsTitle":"Les nouveautés du service","newsContent":"Nouvelles fonctionnalités","question":"pollQuestion","link":"pollLink"`)
do("GET", "/api/common/monthlyReport/2021/1", noH, "", http.StatusOK, `{"year":2021,"month":1,"subject":"[Ecolyo] Votre bilan de décembre 2020","info":"Informations du mois","image":"imagebase64","newsTitle":"Les nouveautés du service","newsContent":"Nouvelles fonctionnalités","question":"pollQuestion","link":"pollLink"`)
// Try to update the partnersInfo (must pass)
do("PUT", "/api/admin/partnersInfo", xsrfHeader, partnersInfoStr, http.StatusOK, partnersInfoStr)
......@@ -219,7 +219,7 @@ func adminTests(t *testing.T) {
// Try to get a mail subject after it is deleted (must fail because not found)
do("GET", "/api/admin/mailSubject/2021/1", xsrfHeader, "", http.StatusNotFound, "")
// Try to get the monthlyReport (must pass)
do("GET", "/api/common/monthlyReport/2021/1", noH, "", http.StatusOK, `{"year":2021,"month":1,"subject":"[Ecolyo] Votre bilan de janvier 2021","info":"Informations du mois","image":"imagebase64","newsTitle":"","newsContent":"","question":"","link":""`)
do("GET", "/api/common/monthlyReport/2021/1", noH, "", http.StatusOK, `{"year":2021,"month":1,"subject":"[Ecolyo] Votre bilan de décembre 2020","info":"Informations du mois","image":"imagebase64","newsTitle":"","newsContent":"","question":"","link":""`)
}
// Try to login (must pass)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment