From 855f9682c59fa2ab6a13006674e68e73c9c2499e Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Tue, 12 Mar 2024 21:24:10 +0100 Subject: [PATCH] fixed the testcases for the feedback --- .../cron/email_templates/feedback_body.gohtml | 4 ++-- .../cron/email_templates/feedback_body.txt.tmpl | 4 ++-- server/backend/cron/feedback_email.go | 6 +++--- server/backend/cron/feedback_email_test.go | 14 +++++++------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/server/backend/cron/email_templates/feedback_body.gohtml b/server/backend/cron/email_templates/feedback_body.gohtml index 411eb53e..b5dd640c 100644 --- a/server/backend/cron/email_templates/feedback_body.gohtml +++ b/server/backend/cron/email_templates/feedback_body.gohtml @@ -1,7 +1,7 @@

Feedback via TumCampusApp:

-{{ if .Feedback.Valid -}} +{{ if .Feedback -}}
- {{- .Feedback.String -}} + {{- .Feedback -}}
{{- else -}} no feedback provided diff --git a/server/backend/cron/email_templates/feedback_body.txt.tmpl b/server/backend/cron/email_templates/feedback_body.txt.tmpl index e4c6c7d0..b4b2cc16 100644 --- a/server/backend/cron/email_templates/feedback_body.txt.tmpl +++ b/server/backend/cron/email_templates/feedback_body.txt.tmpl @@ -1,7 +1,7 @@ Feedback via TumCampusApp: -{{ if .Feedback.Valid }} -{{- .Feedback.String -}} +{{ if .Feedback }} +{{- .Feedback -}} {{ else -}} no feedback provided {{- end }} diff --git a/server/backend/cron/feedback_email.go b/server/backend/cron/feedback_email.go index 3e4c770e..ff6841c6 100644 --- a/server/backend/cron/feedback_email.go +++ b/server/backend/cron/feedback_email.go @@ -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", "app@tum.de") + m.SetHeader("To", "app@tum.de") // should not ever happen as checked in the api } // ReplyTo if feedback.ReplyTo.Valid { diff --git a/server/backend/cron/feedback_email_test.go b/server/backend/cron/feedback_email_test.go index 90dd0d16..1c072c37 100644 --- a/server/backend/cron/feedback_email_test.go +++ b/server/backend/cron/feedback_email_test.go @@ -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("test@example.de"), - Feedback: null.StringFrom("This is a Test"), + Feedback: "This is a Test", ImageCount: 1, Latitude: null.FloatFrom(0), Longitude: null.FloatFrom(0), @@ -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{}, @@ -56,7 +56,7 @@ func TestHeaderInstantiationWithFullFeedback(t *testing.T) { fb := fullFeedback() m := messageWithHeaders(fb) assert.Equal(t, []string{`"TUM Campus App" `}, 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{"test@example.de"}, 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"))