From ecc07a39117613446c4dfdf855212161b9af8dc4 Mon Sep 17 00:00:00 2001 From: Vishal Date: Mon, 31 Oct 2022 19:26:04 +0530 Subject: [PATCH] fix no-cloud-limit error (#21447) --- app/post.go | 5 ++++ app/post_test.go | 66 +++++++++++++++++++++++++++++++++--------------- 2 files changed, 51 insertions(+), 20 deletions(-) diff --git a/app/post.go b/app/post.go index a204bc8119..1ad54f19f7 100644 --- a/app/post.go +++ b/app/post.go @@ -1440,6 +1440,11 @@ func (a *App) ComputeLastAccessiblePostTime() error { return appErr } + if limit == 0 { + // Cloud limit is not applicable + return nil + } + createdAt, err := a.Srv().GetStore().Post().GetNthRecentPostTime(limit) if err != nil { var nfErr *store.ErrNotFound diff --git a/app/post_test.go b/app/post_test.go index 3315ada6f9..96ca119187 100644 --- a/app/post_test.go +++ b/app/post_test.go @@ -2857,32 +2857,58 @@ func TestGetLastAccessiblePostTime(t *testing.T) { } func TestComputeLastAccessiblePostTime(t *testing.T) { - th := SetupWithStoreMock(t) - defer th.TearDown() + t.Run("Updates the time, if cloud limit is applicable", func(t *testing.T) { + th := SetupWithStoreMock(t) + defer th.TearDown() - th.App.Srv().SetLicense(model.NewTestLicense("cloud")) + th.App.Srv().SetLicense(model.NewTestLicense("cloud")) - cloud := &eMocks.CloudInterface{} - th.App.Srv().Cloud = cloud + cloud := &eMocks.CloudInterface{} + th.App.Srv().Cloud = cloud - cloud.Mock.On("GetCloudLimits", mock.Anything).Return(&model.ProductLimits{ - Messages: &model.MessagesLimits{ - History: model.NewInt(1), - }, - }, nil) + // cloud-starter, limit is applicable + cloud.Mock.On("GetCloudLimits", mock.Anything).Return(&model.ProductLimits{ + Messages: &model.MessagesLimits{ + History: model.NewInt(1), + }, + }, nil) - mockStore := th.App.Srv().Store().(*storemocks.Store) - mockPostStore := storemocks.PostStore{} - mockPostStore.On("GetNthRecentPostTime", mock.Anything).Return(int64(1), nil) - mockSystemStore := storemocks.SystemStore{} - mockSystemStore.On("SaveOrUpdate", mock.Anything).Return(nil) - mockStore.On("Post").Return(&mockPostStore) - mockStore.On("System").Return(&mockSystemStore) + mockStore := th.App.Srv().Store().(*storemocks.Store) + mockPostStore := storemocks.PostStore{} + mockPostStore.On("GetNthRecentPostTime", mock.Anything).Return(int64(1), nil) + mockSystemStore := storemocks.SystemStore{} + mockSystemStore.On("SaveOrUpdate", mock.Anything).Return(nil) + mockStore.On("Post").Return(&mockPostStore) + mockStore.On("System").Return(&mockSystemStore) - err := th.App.ComputeLastAccessiblePostTime() - assert.NoError(t, err) + err := th.App.ComputeLastAccessiblePostTime() + assert.NoError(t, err) - mockSystemStore.AssertCalled(t, "SaveOrUpdate", mock.Anything) + mockSystemStore.AssertCalled(t, "SaveOrUpdate", mock.Anything) + }) + + t.Run("Do NOT update the time, if cloud limit is NOT applicable", func(t *testing.T) { + th := SetupWithStoreMock(t) + defer th.TearDown() + + th.App.Srv().SetLicense(model.NewTestLicense("cloud")) + + cloud := &eMocks.CloudInterface{} + th.App.Srv().Cloud = cloud + + // enterprise, limit is NOT applicable + cloud.Mock.On("GetCloudLimits", mock.Anything).Return(nil, nil) + + mockStore := th.App.Srv().Store().(*storemocks.Store) + mockSystemStore := storemocks.SystemStore{} + mockSystemStore.On("SaveOrUpdate", mock.Anything).Return(nil) + mockStore.On("System").Return(&mockSystemStore) + + err := th.App.ComputeLastAccessiblePostTime() + assert.NoError(t, err) + + mockSystemStore.AssertNotCalled(t, "SaveOrUpdate", mock.Anything) + }) } func TestGetTopThreadsForTeamSince(t *testing.T) {