Skip to content

Commit

Permalink
tests: Add a mocked test for EmojiReaction being called in github
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusramberg committed Apr 19, 2023
1 parent dbf4e43 commit 682d86c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 15 deletions.
21 changes: 21 additions & 0 deletions server/controllers/events/events_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,25 @@ func TestPost_GithubCommentSuccess(t *testing.T) {
cr.VerifyWasCalledOnce().RunCommentCommand(baseRepo, nil, nil, user, 1, &cmd)
}

func TestPost_GithubCommentReaction(t *testing.T) {
t.Log("when the event is a github comment with a valid command we call the command handler")
e, v, _, _, p, _, _, vcsClient, cp := setup(t)
req, _ := http.NewRequest("GET", "", bytes.NewBuffer(nil))
req.Header.Set(githubHeader, "issue_comment")
event := `{"action": "created", "comment": {"body": "atlantis help", "id": 1}}`
When(v.Validate(req, secret)).ThenReturn([]byte(event), nil)
baseRepo := models.Repo{}
user := models.User{}
cmd := events.CommentCommand{}
When(p.ParseGithubIssueCommentEvent(matchers.AnyPtrToGithubIssueCommentEvent())).ThenReturn(baseRepo, user, 1, nil)
When(cp.Parse("", models.Github)).ThenReturn(events.CommentParseResult{Command: &cmd})
w := httptest.NewRecorder()
e.Post(w, req)
ResponseContains(t, w, http.StatusOK, "Processing...")

vcsClient.VerifyWasCalledOnce().ReactToComment(baseRepo, 1, "eyes")
}

func TestPost_GithubPullRequestInvalid(t *testing.T) {
t.Log("when the event is a github pull request with invalid data we return a 400")
e, v, _, _, p, _, _, _, _ := setup(t)
Expand Down Expand Up @@ -922,6 +941,8 @@ func setup(t *testing.T) (events_controllers.VCSEventsController, *mocks.MockGit
logger := logging.NewNoopLogger(t)
scope, _, _ := metrics.NewLoggingScope(logger, "null")
e := events_controllers.VCSEventsController{
ExecutableName: "atlantis",
EmojiReaction: "eyes",
TestingMode: true,
Logger: logger,
Scope: scope,
Expand Down
65 changes: 50 additions & 15 deletions server/events/vcs/mocks/mock_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 682d86c

Please sign in to comment.