From 190d4c48b4d0e9a9c0f46efd525e2cb98fe72df4 Mon Sep 17 00:00:00 2001 From: TheInvincible <139259364+TheInvincibleRalph@users.noreply.github.com> Date: Fri, 13 Sep 2024 18:43:54 +0100 Subject: [PATCH] MM-56994 Used false as default for useMilitaryTime (#28128) * used false as default for useMilitaryTime * added test for user time-format preference --- server/channels/app/notification_email.go | 2 +- .../channels/app/notification_email_test.go | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/server/channels/app/notification_email.go b/server/channels/app/notification_email.go index 755548196d..59d251d724 100644 --- a/server/channels/app/notification_email.go +++ b/server/channels/app/notification_email.go @@ -71,7 +71,7 @@ func (a *App) sendNotificationEmail(c request.CTX, notification *PostNotificatio var useMilitaryTime bool if data, err := a.Srv().Store().Preference().Get(user.Id, model.PreferenceCategoryDisplaySettings, model.PreferenceNameUseMilitaryTime); err != nil { - useMilitaryTime = true + useMilitaryTime = false } else { useMilitaryTime = data.Value == "true" } diff --git a/server/channels/app/notification_email_test.go b/server/channels/app/notification_email_test.go index 967241811d..f7249e93b1 100644 --- a/server/channels/app/notification_email_test.go +++ b/server/channels/app/notification_email_test.go @@ -340,6 +340,50 @@ func TestGetNotificationEmailBodyFullNotificationLocaleTime24Hour(t *testing.T) require.Contains(t, body, "14:30", fmt.Sprintf("Expected email text '14:30'. Got %s", body)) } +func TestGetNotificationEmailBodyWithUserPreference(t *testing.T) { + th := SetupWithStoreMock(t) + defer th.TearDown() + + recipient := &model.User{ + Timezone: timezones.DefaultUserTimezone(), + } + recipient.Timezone["automaticTimezone"] = "America/New_York" + + post := &model.Post{ + CreateAt: 1524681000000, + Message: "This is the message", + } + + channel := &model.Channel{ + DisplayName: "ChannelName", + Type: model.ChannelTypeDirect, + } + + channelName := "ChannelName" + senderName := "sender" + teamName := "testteam" + teamURL := "http://localhost:8065/testteam" + emailNotificationContentsType := model.EmailNotificationContentsFull + translateFunc := i18n.GetUserTranslations("en") + + storeMock := th.App.Srv().Store().(*mocks.Store) + teamStoreMock := mocks.TeamStore{} + teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil) + storeMock.On("Team").Return(&teamStoreMock) + + // Test 12-hour format + is24HourFormat := false + + expectedTimeFormat := "2:30 PM" + if is24HourFormat { + expectedTimeFormat = "14:30" + } + + body, err := th.App.getNotificationEmailBody(th.Context, recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, is24HourFormat, translateFunc, "user-avatar.png") + require.NoError(t, err) + require.Contains(t, body, expectedTimeFormat, fmt.Sprintf("Expected email text '%s'. Got %s", expectedTimeFormat, body)) +} + func TestGetNotificationEmailBodyFullNotificationWithSlackAttachments(t *testing.T) { th := SetupWithStoreMock(t) defer th.TearDown()