Skip to content

Commit

Permalink
fixed the testcases for the feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Mar 12, 2024
1 parent 5fa5c8e commit 855f968
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions server/backend/cron/email_templates/feedback_body.gohtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1>Feedback via TumCampusApp:</h1>
{{ if .Feedback.Valid -}}
{{ if .Feedback -}}
<blockquote>
{{- .Feedback.String -}}
{{- .Feedback -}}
</blockquote>
{{- else -}}
<i>no feedback provided</i>
Expand Down
4 changes: 2 additions & 2 deletions server/backend/cron/email_templates/feedback_body.txt.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feedback via TumCampusApp:

{{ if .Feedback.Valid }}
{{- .Feedback.String -}}
{{ if .Feedback }}
{{- .Feedback -}}
{{ else -}}
no feedback provided
{{- end }}
Expand Down
6 changes: 3 additions & 3 deletions server/backend/cron/feedback_email.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ func messageWithHeaders(feedback *model.Feedback) *gomail.Message {
// From
m.SetAddressHeader("From", os.Getenv("SMTP_USERNAME"), "TUM Campus App")
// To
if feedback.Recipient.Valid {
m.SetHeader("To", feedback.Recipient.String)
if feedback.Recipient != "" {
m.SetHeader("To", feedback.Recipient)
} else {
m.SetHeader("To", "[email protected]")
m.SetHeader("To", "[email protected]") // should not ever happen as checked in the api
}
// ReplyTo
if feedback.ReplyTo.Valid {
Expand Down
14 changes: 7 additions & 7 deletions server/backend/cron/feedback_email_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ func TestIterate(t *testing.T) {

func fullFeedback() *model.Feedback {
return &model.Feedback{
EmailId: null.StringFrom("magic-id"),
Recipient: null.StringFrom("tca"),
EmailId: "magic-id",
Recipient: "tca",
ReplyTo: null.StringFrom("[email protected]"),
Feedback: null.StringFrom("This is a Test"),
Feedback: "This is a Test",
ImageCount: 1,
Latitude: null.FloatFrom(0),
Longitude: null.FloatFrom(0),
Expand All @@ -38,10 +38,10 @@ func fullFeedback() *model.Feedback {

func emptyFeedback() *model.Feedback {
return &model.Feedback{
EmailId: null.String{},
Recipient: null.String{},
EmailId: "",
Recipient: "",
ReplyTo: null.String{},
Feedback: null.String{},
Feedback: "",
ImageCount: 0,
Latitude: null.Float{},
Longitude: null.Float{},
Expand All @@ -56,7 +56,7 @@ func TestHeaderInstantiationWithFullFeedback(t *testing.T) {
fb := fullFeedback()
m := messageWithHeaders(fb)
assert.Equal(t, []string{`"TUM Campus App" <[email protected]>`}, m.GetHeader("From"))
assert.Equal(t, []string{fb.Recipient.String}, m.GetHeader("To"))
assert.Equal(t, []string{fb.Recipient}, m.GetHeader("To"))
assert.Equal(t, []string{"[email protected]"}, m.GetHeader("Reply-To"))
assert.Equal(t, []string{fb.Timestamp.Time.Format(time.RFC1123Z)}, m.GetHeader("Date"))
assert.Equal(t, []string{"Feedback via Tum Campus App"}, m.GetHeader("Subject"))
Expand Down

0 comments on commit 855f968

Please sign in to comment.