public async Task ReceiveMergeCommand_AllChecksPassed_PrHasChangesRequested_WriteErrorComment() { var payloadString = await File.ReadAllTextAsync("../../../DummyEvents/IssueComment.json"); var payload = JsonConvert.DeserializeObject <dynamic>(payloadString); var owner = Guid.NewGuid().ToString(); var repo = Guid.NewGuid().ToString(); payload["repository"]["name"] = repo; payload["repository"]["owner"]["login"] = owner; await checkListsCollection.InsertWithDefaultChecks(owner, repo); await mergeRequestsCollection.InsertWithTestChecksSuccess(owner, repo, PR_ID); await repoConfigurationCollection.Insert(owner, repo); var requestedReviewsMockedResponse = new { teams = Array.Empty <object>(), users = Array.Empty <object>() }; var reviewsMockedResponse = new[] { new { User = new { login = "******", id = 3 }, State = "CHANGES_REQUESTED" } }; await MockReviewGithubCallHelper.MockReviewsResponses(JsonConvert.SerializeObject(requestedReviewsMockedResponse), JsonConvert.SerializeObject(reviewsMockedResponse), owner, repo, PR_ID); var commentChangesRequestedCallId = await MockCommentGithubCallHelper.MockCommentGithubCallRequestedChanges(owner, repo, PR_ID, "itay"); await SendWebhookRequest("issue_comment", JsonConvert.SerializeObject(payload)); // ASSERT var commentChangesRequestedCall = await GetCall(commentChangesRequestedCallId); Assert.True(commentChangesRequestedCall.HasBeenMade, "comment should have been written"); var mergeRequest = await mergeRequestsCollection.Collection.Find(d => d["Owner"] == owner && d["Repo"] == repo && d["PrId"] == PR_ID && d["ReceivedMergeCommand"] == true).FirstAsync(); Assert.NotNull(mergeRequest); }
public async Task ActionIsCompleted_ConclusionIsSuccess_PendingReviews_PrIsNotMergable_DoNothing() { var payloadString = await File.ReadAllTextAsync("../../../DummyEvents/Status.json"); var payload = JsonConvert.DeserializeObject <dynamic>(payloadString); var owner = Guid.NewGuid().ToString(); var repo = Guid.NewGuid().ToString(); var sha = Guid.NewGuid().ToString(); await checkListsCollection.InsertWithDefaultChecks(owner, repo); var checksAlreadyCompleted = new List <CheckStatus>() { new CheckStatus { Name = Consts.TEST_CHECK_A, Status = "success" } }; payload["repository"]["name"] = repo; payload["repository"]["owner"]["login"] = owner; payload["state"] = "success"; payload["sha"] = sha; payload["context"] = Consts.TEST_CHECK_B; await mergeRequestsCollection.Insert(owner, repo, PR_ID, Consts.DEFAULT_BRANCH, true, checksAlreadyCompleted, sha); var mergePrCallId = await MockMergeGithubCallHelper.MockMergeCall(owner, repo, PR_ID); var createCommentCallId = await MockGithubCall("post", $"{IssueUrlFor(owner, repo, PR_ID)}/comments", "ok", false); var requestedReviewsMockedResponse = new { teams = Array.Empty <object>(), users = new[] { new { login = "******", id = 3 } } }; await MockReviewGithubCallHelper.MockReviewsResponses(JsonConvert.SerializeObject(requestedReviewsMockedResponse), "[]", owner, repo, PR_ID); await SendWebhookRequest("status", JsonConvert.SerializeObject(payload)); var mergePrCall = await GetCall(mergePrCallId); var mergeRequest = await mergeRequestsCollection.Collection.Find(d => d["Owner"] == owner && d["Repo"] == repo && d["PrId"] == PR_ID).FirstAsync(); Assert.False(mergePrCall.HasBeenMade, "the pr shouldn't be merged"); }
public async Task ReceiveInfoCommand_AllChecksPassed_PrHasPendingReviews_WriteErrorComment() { var payloadString = await File.ReadAllTextAsync("../../../DummyEvents/IssueComment.json"); var payload = JsonConvert.DeserializeObject <dynamic>(payloadString); var owner = Guid.NewGuid().ToString(); var repo = Guid.NewGuid().ToString(); // Insert Checkslist and PR to DB await checkListsCollection.InsertWithDefaultChecks(owner, repo); await mergeRequestsCollection.InsertWithTestChecksSuccess(owner, repo, PR_ID); payload["repository"]["name"] = repo; payload["repository"]["owner"]["login"] = owner; payload["issue"]["number"] = PR_ID; payload["comment"]["body"] = "Miro info"; var requestedReviewsMockedResponse = new { teams = Array.Empty <object>(), users = new[] { new { login = "******", id = 3 } } }; // Mock Github Calls await MockReviewGithubCallHelper.MockReviewsResponses(JsonConvert.SerializeObject(requestedReviewsMockedResponse), "[]", owner, repo, PR_ID); var failureCommentCallId = await MockCommentGithubCallHelper.MockCommentGithubCallPendingReviews(owner, repo, PR_ID, "itay"); // ACTION await SendWebhookRequest("issue_comment", JsonConvert.SerializeObject(payload)); // ASSERT var failureCommentCall = await GetCall(failureCommentCallId); Assert.True(failureCommentCall.HasBeenMade, "Should have recieved a failure comment"); }