Skip to content

Commit

Permalink
Merge branch 'develop' into feature/switch-to-use-renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
jondewijones committed Aug 9, 2022
2 parents dc09f59 + e494a0a commit 922bb30
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 55 deletions.
26 changes: 1 addition & 25 deletions handlers/feedback.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,6 @@ type Feedback struct {
FeedbackFormType string `schema:"feedback-form-type"`
}

// FeedbackThanks loads the Feedback Thank you page
func FeedbackThanks(rend interfaces.Renderer) http.HandlerFunc {
return dphandlers.ControllerHandler(func(w http.ResponseWriter, req *http.Request, lang, collectionID, accessToken string) {
feedbackThanks(w, req, rend)
})
}

func feedbackThanks(w http.ResponseWriter, req *http.Request, rend interfaces.Renderer) {
basePage := rend.NewBasePageModel()
p := model.Feedback{
Page: basePage,
}

p.Metadata.Title = "Thank you"
returnTo := req.URL.Query().Get("returnTo")

if returnTo == "Whole site" || returnTo == "" {
returnTo = "https://www.ons.gov.uk"
}
p.Metadata.Description = returnTo

rend.BuildPage(w, p, "feedback-thank-you")
}

// GetFeedback handles the loading of a feedback page
func GetFeedback(rend interfaces.Renderer) http.HandlerFunc {
return dphandlers.ControllerHandler(func(w http.ResponseWriter, req *http.Request, lang, collectionID, accessToken string) {
Expand Down Expand Up @@ -137,7 +113,7 @@ func addFeedback(w http.ResponseWriter, req *http.Request, isPositive bool, rend
return
}

redirectURL := "/feedback/thanks?returnTo=" + f.URL
redirectURL := "/feedback?returnTo=" + f.URL
http.Redirect(w, req, redirectURL, http.StatusMovedPermanently)
}

Expand Down
29 changes: 0 additions & 29 deletions handlers/feedback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,32 +299,3 @@ func Test_addFeedback(t *testing.T) {
})
})
}

func Test_feedbackThanks(t *testing.T) {

Convey("Given a valid request", t, func() {

req := httptest.NewRequest("GET", "http://localhost", nil)
w := httptest.NewRecorder()

mockRenderer := &interfacestest.RendererMock{
BuildPageFunc: func(w io.Writer, pageModel interface{}, templateName string) {},
NewBasePageModelFunc: func() coreModel.Page {
return coreModel.Page{}
},
}

Convey("When feedbackThanks is called", func() {

feedbackThanks(w, req, mockRenderer)

Convey("Then the renderer is called", func() {
So(len(mockRenderer.BuildPageCalls()), ShouldEqual, 1)
})

Convey("Then a 200 response is returned", func() {
So(w.Code, ShouldEqual, http.StatusOK)
})
})
})
}
1 change: 0 additions & 1 deletion routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func Setup(ctx context.Context, r *mux.Router, cfg *config.Config, rend *render.
r.StrictSlash(true).Path("/feedback").Methods("POST").HandlerFunc(handlers.AddFeedback(cfg.FeedbackTo, cfg.FeedbackFrom, false, rend, emailSender))
r.StrictSlash(true).Path("/feedback/positive").Methods("POST").HandlerFunc(handlers.AddFeedback(cfg.FeedbackTo, cfg.FeedbackFrom, false, rend, emailSender))
r.StrictSlash(true).Path("/feedback").Methods("GET").HandlerFunc(handlers.GetFeedback(rend))
r.StrictSlash(true).Path("/feedback/thanks").Methods("GET").HandlerFunc(handlers.FeedbackThanks(rend))

}

Expand Down

0 comments on commit 922bb30

Please sign in to comment.