Ignore ack and notification counts if notifications are blocked by the device (#27570)
* Ignore performance counts if notifications are blocked by the device * Change the endpoint to allow more information * Add tests and API description * Remove wrong test * Address feedback * Only update the cache when there is no error * Follow same casing as other props * use one single endpoint * Fix tests * Fix i18n --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
b9debc75a0
Коммит
af503d9d45
@@ -3691,7 +3691,7 @@ func TestAttachDeviceId(t *testing.T) {
|
||||
*cfg.ServiceSettings.SiteURL = tc.SiteURL
|
||||
})
|
||||
|
||||
resp, err := th.Client.AttachDeviceId(context.Background(), deviceId)
|
||||
resp, err := th.Client.AttachDeviceProps(context.Background(), map[string]string{"device_id": deviceId})
|
||||
require.NoError(t, err)
|
||||
|
||||
cookies := resp.Header.Get("Set-Cookie")
|
||||
@@ -3704,19 +3704,88 @@ func TestAttachDeviceId(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("invalid device id", func(t *testing.T) {
|
||||
resp, err := th.Client.AttachDeviceId(context.Background(), "")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("not logged in", func(t *testing.T) {
|
||||
th.Client.Logout(context.Background())
|
||||
|
||||
resp, err := th.Client.AttachDeviceId(context.Background(), "")
|
||||
resp, err := th.Client.AttachDeviceProps(context.Background(), map[string]string{})
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
})
|
||||
|
||||
// Props related tests
|
||||
|
||||
client := th.CreateClient()
|
||||
th.LoginBasicWithClient(client)
|
||||
|
||||
resetSession := func(session *model.Session) {
|
||||
session.AddProp(model.SessionPropDeviceNotificationDisabled, "")
|
||||
session.AddProp(model.SessionPropMobileVersion, "")
|
||||
th.Server.Store().Session().UpdateProps(session)
|
||||
th.App.ClearSessionCacheForUser(session.UserId)
|
||||
}
|
||||
|
||||
t.Run("No props will return ok and no changes in the session", func(t *testing.T) {
|
||||
session, _ := th.App.GetSession(client.AuthToken)
|
||||
defer resetSession(session)
|
||||
res, err := client.AttachDeviceProps(context.Background(), map[string]string{})
|
||||
assert.NoError(t, err)
|
||||
|
||||
updatedSession, _ := th.App.GetSession(client.AuthToken)
|
||||
storeSession, _ := th.Server.Store().Session().Get(th.Context, session.Id)
|
||||
assert.Equal(t, http.StatusOK, res.StatusCode)
|
||||
assert.Equal(t, session.Props, updatedSession.Props)
|
||||
assert.Equal(t, session.Props, storeSession.Props)
|
||||
})
|
||||
t.Run("Unknown props will be ignored, returning ok and no changes in the session", func(t *testing.T) {
|
||||
session, _ := th.App.GetSession(client.AuthToken)
|
||||
defer resetSession(session)
|
||||
res, err := client.AttachDeviceProps(context.Background(), map[string]string{"unknownProp": "foo"})
|
||||
assert.NoError(t, err)
|
||||
|
||||
updatedSession, _ := th.App.GetSession(client.AuthToken)
|
||||
storeSession, _ := th.Server.Store().Session().Get(th.Context, session.Id)
|
||||
assert.Equal(t, http.StatusOK, res.StatusCode)
|
||||
assert.Equal(t, session.Props, updatedSession.Props)
|
||||
assert.Equal(t, session.Props, storeSession.Props)
|
||||
})
|
||||
t.Run("Invalid disabled notification prop will return an error and no changes in the session", func(t *testing.T) {
|
||||
session, _ := th.App.GetSession(client.AuthToken)
|
||||
defer resetSession(session)
|
||||
res, err := client.AttachDeviceProps(context.Background(), map[string]string{model.SessionPropDeviceNotificationDisabled: "foo"})
|
||||
assert.Error(t, err)
|
||||
|
||||
updatedSession, _ := th.App.GetSession(client.AuthToken)
|
||||
storeSession, _ := th.Server.Store().Session().Get(th.Context, session.Id)
|
||||
assert.Equal(t, http.StatusBadRequest, res.StatusCode)
|
||||
assert.Equal(t, session.Props, updatedSession.Props)
|
||||
assert.Equal(t, session.Props, storeSession.Props)
|
||||
})
|
||||
t.Run("Invalid version will return an error and no changes in the session", func(t *testing.T) {
|
||||
session, _ := th.App.GetSession(client.AuthToken)
|
||||
defer resetSession(session)
|
||||
res, err := client.AttachDeviceProps(context.Background(), map[string]string{model.SessionPropMobileVersion: "foo"})
|
||||
assert.Error(t, err)
|
||||
|
||||
updatedSession, _ := th.App.GetSession(client.AuthToken)
|
||||
storeSession, _ := th.Server.Store().Session().Get(th.Context, session.Id)
|
||||
assert.Equal(t, http.StatusBadRequest, res.StatusCode)
|
||||
assert.Equal(t, session.Props, updatedSession.Props)
|
||||
assert.Equal(t, session.Props, storeSession.Props)
|
||||
})
|
||||
t.Run("Will update props", func(t *testing.T) {
|
||||
session, _ := th.App.GetSession(client.AuthToken)
|
||||
defer resetSession(session)
|
||||
res, err := client.AttachDeviceProps(context.Background(), map[string]string{model.SessionPropDeviceNotificationDisabled: "true", model.SessionPropMobileVersion: "2.19.0"})
|
||||
assert.NoError(t, err)
|
||||
|
||||
updatedSession, _ := th.App.GetSession(client.AuthToken)
|
||||
storeSession, _ := th.Server.Store().Session().Get(th.Context, session.Id)
|
||||
assert.Equal(t, http.StatusOK, res.StatusCode)
|
||||
assert.Equal(t, "true", updatedSession.Props[model.SessionPropDeviceNotificationDisabled])
|
||||
assert.Equal(t, "true", storeSession.Props[model.SessionPropDeviceNotificationDisabled])
|
||||
assert.Equal(t, "2.19.0", updatedSession.Props[model.SessionPropMobileVersion])
|
||||
assert.Equal(t, "2.19.0", storeSession.Props[model.SessionPropMobileVersion])
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetUserAudits(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user