Skip to content

Commit

Permalink
Add server testcases for store/user_store.go (#432)
Browse files Browse the repository at this point in the history
* [MM-844]: Added server testcase for store/welcome_store.go

* [MM-844]: Updated the go.sum

* [MM-844]: Moved clearing of expected mock calls to loop

* [MM-843]: Added server testcase for kvstore/plugin_store.go file (#18)

* [MM-843]: Added server testcase for kvstore/plugin_store.go file

* [MM-843]: removed ununsed vars

* updated go.mod and go.sum entries

* refactored mock plugin setup

* [MM-844]: refactored the code

* [MM-844]: Fixed the go sum

* [MM-845]: Added server testcases for store/user_store.go
  • Loading branch information
Kshitij-Katiyar authored Jan 16, 2025
1 parent 39fb290 commit ef5da8b
Show file tree
Hide file tree
Showing 3 changed files with 938 additions and 9 deletions.
56 changes: 55 additions & 1 deletion calendar/store/test_util.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
package store

import (
"encoding/json"
"fmt"
"testing"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/mock"

"github.com/mattermost/mattermost-plugin-mscalendar/calendar/remote"
"github.com/mattermost/mattermost-plugin-mscalendar/calendar/testutil"
"github.com/mattermost/mattermost-plugin-mscalendar/calendar/tracker/mock_tracker"
"github.com/mattermost/mattermost-plugin-mscalendar/calendar/utils/bot/mock_bot"
)

const (
MockMMUsername = "mockMMUsername"
MockMMDisplayName = "mockMMDisplayName"
MockMMUserID = "mockMMUserID"
MockRemoteID = "mockRemoteID"
MockRemoteUserID = "mockRemoteUserID"
MockRemoteMail = "mock@remote.com"
MockEventID = "mockEventID"
MockChannelID = "mockChannelID"
MockUserIndexJSON = `[{"mm_id": "mockMMUserID"}]`
InvalidMockUserIndexJSON = `[{"mm_id": "invalidMockMMUserID"}]`
MockRemoteJSON = `{"remote": {"id": "mockRemoteID"}}`
MockUserJSON = `[{"MattermostUserID":"mockMMUserID","RemoteID":"mockRemoteID"}]`
MockUserDetailsWithEventJSON = `{"mm_id":"mockUserID","active_events": []}`
)

var MockString = mock.AnythingOfType("string")
var MockByteValue = mock.MatchedBy(func(arg interface{}) bool {
_, ok := arg.([]byte)
Expand All @@ -21,11 +40,46 @@ func GetMockSetup(t *testing.T) (*testutil.MockPluginAPI, Store, *mock_bot.MockL
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockLogger := mock_bot.NewMockLogger(ctrl)
mockPoster := mock_bot.NewMockPoster(ctrl)
mockLoggerWith := mock_bot.NewMockLogger(ctrl)
mockTracker := mock_tracker.NewMockTracker(ctrl)
mockPoster := mock_bot.NewMockPoster(ctrl)
mockAPI := &testutil.MockPluginAPI{}
store := NewPluginStore(mockAPI, mockLogger, mockPoster, mockTracker, false, nil)

return mockAPI, store, mockLogger, mockLoggerWith, mockTracker
}

func GetRemoteUserJSON(noOfUsers int) string {
type RemoteUser struct {
MMUsername string `json:"mm_username"`
RemoteID string `json:"remote_id"`
MMID string `json:"mm_id"`
Email string `json:"email"`
}

var users []RemoteUser
for i := 1; i <= noOfUsers; i++ {
user := RemoteUser{
MMUsername: fmt.Sprintf("user%d", i),
RemoteID: fmt.Sprintf("remote%d", i),
MMID: fmt.Sprintf("user%d", i),
Email: fmt.Sprintf("user%d@example.com", i),
}
users = append(users, user)
}

result, _ := json.Marshal(users)
return string(result)
}

func GetMockUser() *User {
return &User{
MattermostUserID: MockMMUserID,
MattermostUsername: MockMMUsername,
MattermostDisplayName: MockMMDisplayName,
Remote: &remote.User{
ID: MockRemoteID,
Mail: MockRemoteMail,
},
}
}
Loading

0 comments on commit ef5da8b

Please sign in to comment.