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

fix: monthlyNews and poll can now be deleted

parent 87aea1a7
No related branches found
No related tags found
3 merge requests!14feat: addprices + subject managment,!11feat: Add partners issue info,!5Feat: Add backoffice
......@@ -3,24 +3,14 @@ module forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server
go 1.15
require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
github.com/go-openapi/jsonreference v0.19.6 // indirect
github.com/go-openapi/spec v0.20.3 // indirect
github.com/go-openapi/swag v0.19.15 // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
github.com/gorilla/mux v1.8.0
github.com/mailru/easyjson v0.7.7 // indirect
github.com/nicolaspernoud/vestibule v0.0.0-20210626100803-e2554e116746
github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14 // indirect
github.com/swaggo/gin-swagger v1.2.0 // indirect
github.com/swaggo/http-swagger v1.0.0 // indirect
github.com/swaggo/swag v1.7.0 // indirect
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e
golang.org/x/net v0.0.0-20210716203947-853a461950ff // indirect
github.com/swaggo/http-swagger v1.0.0
github.com/swaggo/swag v1.7.0
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97
golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
golang.org/x/tools v0.1.5 // indirect
gorm.io/driver/mysql v1.1.1
gorm.io/driver/sqlite v1.1.4
gorm.io/gorm v1.21.11
gorm.io/gorm v1.21.12
)
This diff is collapsed.
......@@ -217,7 +217,7 @@ func DeleteMonthlyNews(w http.ResponseWriter, r *http.Request) {
return
}
year, err := strconv.Atoi(monthStr)
year, err := strconv.Atoi(yearStr)
if err != nil {
http.Error(w, "year is not an integer", http.StatusBadRequest)
return
......
......@@ -217,7 +217,7 @@ func DeletePoll(w http.ResponseWriter, r *http.Request) {
return
}
year, err := strconv.Atoi(monthStr)
year, err := strconv.Atoi(yearStr)
if err != nil {
http.Error(w, "year is not an integer", http.StatusBadRequest)
return
......
......@@ -12,6 +12,7 @@ import (
"forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server/internal/auth"
"forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server/internal/mocks"
"forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server/internal/monthlyNews"
"forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server/internal/poll"
"forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server/internal/tester"
"forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server/internal/tokens"
)
......@@ -20,6 +21,8 @@ var (
oAuth2Server *httptest.Server
newMonthlyNews = monthlyNews.MonthlyNews{Year: 2020, Month: 0, Header: "newsHeader", Quote: "newsQuote"}
newMonthlyNewsStr string
newPoll = poll.Poll{Year: 2020, Month: 0, Question: "pollQuestion", Link: "pollLink"}
newPollStr string
noH map[string]string
)
......@@ -48,6 +51,8 @@ func TestMain(m *testing.M) {
// Convert example objects to string
newMonthlyNewsBytes, _ := json.Marshal(newMonthlyNews)
newMonthlyNewsStr = string(newMonthlyNewsBytes)
newPollBytes, _ := json.Marshal(newPoll)
newPollStr = string(newPollBytes)
code := m.Run()
// Remove the database
......@@ -108,7 +113,7 @@ func adminTests(t *testing.T) {
do("POST", "/api/admin/monthlyNews", noH, newMonthlyNewsStr, http.StatusUnauthorized, "XSRF protection triggered")
// Try to create a monthly news without body (must fail)
do("POST", "/api/admin/monthlyNews", xsrfHeader, "", http.StatusBadRequest, "request body is empty")
// Try to get a monthly news before it is created (must pass)
// Try to get a monthly news before it is created (must pass empty)
do("GET", "/api/admin/monthlyNews/2020/0", xsrfHeader, "", http.StatusOK, "{}")
// Try to create a monthly news (must pass)
do("PUT", "/api/admin/monthlyNews", xsrfHeader, newMonthlyNewsStr, http.StatusCreated, newMonthlyNewsStr)
......@@ -116,8 +121,27 @@ func adminTests(t *testing.T) {
do("PUT", "/api/admin/monthlyNews", xsrfHeader, newMonthlyNewsStr, http.StatusOK, newMonthlyNewsStr)
// Try to get the monthly news created (must pass)
do("GET", "/api/admin/monthlyNews/2020/0", xsrfHeader, "", http.StatusOK, newMonthlyNewsStr)
// Try to delete the monthly news created (must pass)
do("DELETE", "/api/admin/monthlyNews/2020/0", xsrfHeader, "", http.StatusOK, "successful delete")
// Try to get a monthly news after it is deleted (must pass empty)
do("GET", "/api/admin/monthlyNews/2020/0", xsrfHeader, "", http.StatusOK, "{}")
// TODO: Complete tests
// Try to create a poll without the XSRF-TOKEN (must fail)
do("POST", "/api/admin/poll", noH, newPollStr, http.StatusUnauthorized, "XSRF protection triggered")
// Try to create a poll without body (must fail)
do("POST", "/api/admin/poll", xsrfHeader, "", http.StatusBadRequest, "request body is empty")
// Try to get a poll before it is created (must pass empty)
do("GET", "/api/admin/poll/2020/0", xsrfHeader, "", http.StatusOK, "{}")
// Try to create a poll (must pass)
do("PUT", "/api/admin/poll", xsrfHeader, newPollStr, http.StatusCreated, newPollStr)
// Try to update a poll (must pass)
do("PUT", "/api/admin/poll", xsrfHeader, newPollStr, http.StatusOK, newPollStr)
// Try to get the poll created (must pass)
do("GET", "/api/admin/poll/2020/0", xsrfHeader, "", http.StatusOK, newPollStr)
// Try to delete the poll created (must pass)
do("DELETE", "/api/admin/poll/2020/0", xsrfHeader, "", http.StatusOK, "successful delete")
// Try to get a poll after it is deleted (must pass empty)
do("GET", "/api/admin/poll/2020/0", xsrfHeader, "", http.StatusOK, "{}")
}
// Try to login (must pass)
do("GET", "/OAuth2Login", noH, "", http.StatusOK, "successful login")
......@@ -127,6 +151,8 @@ func adminTests(t *testing.T) {
do("GET", "/Logout", noH, "", http.StatusOK, "")
// Try to get a monthly news again (must fail)
do("GET", "/api/admin/monthlyNews", noH, "", http.StatusUnauthorized, "error extracting token")
// Try to get a poll again (must fail)
do("GET", "/api/admin/poll", noH, "", http.StatusUnauthorized, "error extracting token")
}
func createTester(t *testing.T) (*httptest.Server, tester.DoFn, tester.DoFn) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment