Skip to content

Commit

Permalink
MM-56994 Used false as default for useMilitaryTime (mattermost#28128)
Browse files Browse the repository at this point in the history
* used false as default for useMilitaryTime

* added test for user time-format preference
  • Loading branch information
TheInvincibleRalph authored Sep 13, 2024
1 parent 6cece9f commit 190d4c4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/channels/app/notification_email.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
44 changes: 44 additions & 0 deletions server/channels/app/notification_email_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 190d4c4

Please sign in to comment.