Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reactions to issue, commit comment and review payload #1405

Merged
merged 30 commits into from
Jul 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b06097b
add reactions to issue response payload
martinscholz83 Jun 21, 2016
71e5eab
add reactions to commit comment payload
martinscholz83 Jun 21, 2016
1f9aa88
add reactions to review comment payload
martinscholz83 Jun 21, 2016
6a2ad51
create tests for issue client
martinscholz83 Jun 21, 2016
0f8f345
tests for commitcomment client
martinscholz83 Jun 23, 2016
3cd92ef
tests for pull request review comment
martinscholz83 Jun 23, 2016
93b4d98
change observable tests
martinscholz83 Jun 23, 2016
30cbd8e
simplify strings
martinscholz83 Jun 23, 2016
3c88311
remove unnecessary clients
martinscholz83 Jun 23, 2016
05b451b
change integration tests to retrieve all reaction types
martinscholz83 Jun 24, 2016
3ad2800
Merge remote-tracking branch 'refs/remotes/octokit/master' into add-r…
martinscholz83 Jul 4, 2016
6552b2e
create integration test for issue comment client
martinscholz83 Jul 4, 2016
3c636cf
Merge remote-tracking branch 'refs/remotes/octokit/master' into add-r…
martinscholz83 Jul 6, 2016
e1c97fe
fix merge conflicts
martinscholz83 Jul 6, 2016
75ae58d
Merge remote-tracking branch 'refs/remotes/octokit/master' into add-r…
martinscholz83 Jul 7, 2016
730dcd9
fix merge conflicts
martinscholz83 Jul 7, 2016
e588c29
gets tests passing again
shiftkey Jul 7, 2016
43411b8
fix some reaction integration tests
martinscholz83 Jul 7, 2016
1185da2
Fixup unit tests wth preview accepts header
ryangribble Jul 7, 2016
0a7bfc6
Fixup unit tests wth preview accepts header
ryangribble Jul 7, 2016
6535255
Rework reaction payload tests for IssueComments to handle Get, GetAll…
ryangribble Jul 7, 2016
a6179b0
[WIP] reaction payload tests
martinscholz83 Jul 7, 2016
bd10c35
Rework reaction payload tests for IssueComments to handle Get, GetAll…
ryangribble Jul 7, 2016
50cd04c
Rework reaction payload tests for Issues client
ryangribble Jul 7, 2016
9528faa
Rework reaction payload tests for PullRequestReviews client
ryangribble Jul 7, 2016
6770990
Rework reaction payload tests for CommitComments client
ryangribble Jul 7, 2016
8850126
revert maddin's changes
ryangribble Jul 7, 2016
86bc30e
Revert "[WIP] reaction payload tests"
martinscholz83 Jul 7, 2016
1118db3
Merge branch 'reactions-tests' of https://github.com/TattsGroup/octok…
martinscholz83 Jul 7, 2016
d4dc131
Merge pull request #6 from maddin2016/TattsGroup-reactions-tests
martinscholz83 Jul 7, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Octokit.Reactive/Clients/ObservableIssuesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public IObservable<Issue> GetAllForCurrent(IssueRequest request, ApiOptions opti
Ensure.ArgumentNotNull(request, "request");
Ensure.ArgumentNotNull(options, "options");

return _connection.GetAndFlattenAllPages<Issue>(ApiUrls.Issues(), request.ToParametersDictionary(), options);
return _connection.GetAndFlattenAllPages<Issue>(ApiUrls.Issues(), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options);
}

/// <summary>
Expand Down Expand Up @@ -203,7 +203,7 @@ public IObservable<Issue> GetAllForOwnedAndMemberRepositories(IssueRequest reque
Ensure.ArgumentNotNull(request, "request");
Ensure.ArgumentNotNull(options, "options");

return _connection.GetAndFlattenAllPages<Issue>(ApiUrls.IssuesForOwnedAndMember(), request.ToParametersDictionary(), options);
return _connection.GetAndFlattenAllPages<Issue>(ApiUrls.IssuesForOwnedAndMember(), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options);
}

/// <summary>
Expand Down Expand Up @@ -267,7 +267,7 @@ public IObservable<Issue> GetAllForOrganization(string organization, IssueReques
Ensure.ArgumentNotNull(request, "request");
Ensure.ArgumentNotNull(options, "options");

return _connection.GetAndFlattenAllPages<Issue>(ApiUrls.Issues(organization), request.ToParametersDictionary(), options);
return _connection.GetAndFlattenAllPages<Issue>(ApiUrls.Issues(organization), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options);
}

/// <summary>
Expand Down Expand Up @@ -381,7 +381,7 @@ public IObservable<Issue> GetAllForRepository(string owner, string name, Reposit
Ensure.ArgumentNotNull(request, "request");
Ensure.ArgumentNotNull(options, "options");

return _connection.GetAndFlattenAllPages<Issue>(ApiUrls.Issues(owner, name), request.ToParametersDictionary(), options);
return _connection.GetAndFlattenAllPages<Issue>(ApiUrls.Issues(owner, name), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public IObservable<PullRequestReviewComment> GetAll(string owner, string name, i
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");

return _connection.GetAndFlattenAllPages<PullRequestReviewComment>(ApiUrls.PullRequestReviewComments(owner, name, number), options);
return _connection.GetAndFlattenAllPages<PullRequestReviewComment>(ApiUrls.PullRequestReviewComments(owner, name, number), null, AcceptHeaders.ReactionsPreview, options);
}

/// <summary>
Expand Down Expand Up @@ -178,7 +178,7 @@ public IObservable<PullRequestReviewComment> GetAllForRepository(string owner, s
Ensure.ArgumentNotNull(request, "request");
Ensure.ArgumentNotNull(options, "options");

return _connection.GetAndFlattenAllPages<PullRequestReviewComment>(ApiUrls.PullRequestReviewCommentsRepository(owner, name), request.ToParametersDictionary(),
return _connection.GetAndFlattenAllPages<PullRequestReviewComment>(ApiUrls.PullRequestReviewCommentsRepository(owner, name), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview,
options);
}

Expand All @@ -194,7 +194,10 @@ public IObservable<PullRequestReviewComment> GetAllForRepository(int repositoryI
Ensure.ArgumentNotNull(request, "request");
Ensure.ArgumentNotNull(options, "options");

return _connection.GetAndFlattenAllPages<PullRequestReviewComment>(ApiUrls.PullRequestReviewCommentsRepository(repositoryId), request.ToParametersDictionary(),
return _connection.GetAndFlattenAllPages<PullRequestReviewComment>(
ApiUrls.PullRequestReviewCommentsRepository(repositoryId),
request.ToParametersDictionary(),
AcceptHeaders.ReactionsPreview,
options);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public IObservable<CommitComment> GetAllForRepository(string owner, string name,
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");

return _connection.GetAndFlattenAllPages<CommitComment>(ApiUrls.CommitComments(owner, name), options);
return _connection.GetAndFlattenAllPages<CommitComment>(ApiUrls.CommitComments(owner, name), null, AcceptHeaders.ReactionsPreview, options);
}

/// <summary>
Expand All @@ -100,7 +100,7 @@ public IObservable<CommitComment> GetAllForRepository(int repositoryId, ApiOptio
{
Ensure.ArgumentNotNull(options, "options");

return _connection.GetAndFlattenAllPages<CommitComment>(ApiUrls.CommitComments(repositoryId), options);
return _connection.GetAndFlattenAllPages<CommitComment>(ApiUrls.CommitComments(repositoryId), null, AcceptHeaders.ReactionsPreview, options);
}

/// <summary>
Expand Down Expand Up @@ -147,7 +147,7 @@ public IObservable<CommitComment> GetAllForCommit(string owner, string name, str
Ensure.ArgumentNotNullOrEmptyString(sha, "sha");
Ensure.ArgumentNotNull(options, "options");

return _connection.GetAndFlattenAllPages<CommitComment>(ApiUrls.CommitComments(owner, name, sha), options);
return _connection.GetAndFlattenAllPages<CommitComment>(ApiUrls.CommitComments(owner, name, sha), null, AcceptHeaders.ReactionsPreview, options);
}

/// <summary>
Expand All @@ -162,7 +162,7 @@ public IObservable<CommitComment> GetAllForCommit(int repositoryId, string sha,
Ensure.ArgumentNotNullOrEmptyString(sha, "sha");
Ensure.ArgumentNotNull(options, "options");

return _connection.GetAndFlattenAllPages<CommitComment>(ApiUrls.CommitComments(repositoryId, sha), options);
return _connection.GetAndFlattenAllPages<CommitComment>(ApiUrls.CommitComments(repositoryId, sha), null, AcceptHeaders.ReactionsPreview, options);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public async Task CanCreateReaction()
{
var newReaction = new NewReaction(reactionType);

var reaction = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, newReaction);
var reaction = await _github.Reaction.IssueComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, newReaction);

Assert.IsType<Reaction>(reaction);
Assert.Equal(reactionType, reaction.Content);
Expand Down
156 changes: 149 additions & 7 deletions Octokit.Tests.Integration/Clients/IssueCommentsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@
using Octokit.Tests.Integration;
using Octokit.Tests.Integration.Helpers;
using Xunit;
using System;
using System.Linq;
using System.Collections.Generic;

public class IssueCommentsClientTests
{
public class TheGetMethod
{
readonly IGitHubClient _github;
readonly IIssueCommentsClient _issueCommentsClient;

const string owner = "octokit";
const string name = "octokit.net";
const int id = 12067722;
const int repositoryId = 7528679;

public TheGetMethod()
{
var github = Helper.GetAuthenticatedClient();
_github = Helper.GetAuthenticatedClient();

_issueCommentsClient = github.Issue.Comment;
_issueCommentsClient = _github.Issue.Comment;
}

[IntegrationTest]
Expand All @@ -37,10 +41,37 @@ public async Task ReturnsIssueCommentWithRepositoryId()

Assert.NotNull(comment);
}

[IntegrationTest]
public async Task CanGetReactionPayload()
{
using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("IssueCommentsReactionTests")))
{
// Create a test issue
var issueNumber = await HelperCreateIssue(context.RepositoryOwner, context.RepositoryName);

// Create a test comment with reactions
var commentId = await HelperCreateIssueCommentWithReactions(context.RepositoryOwner, context.RepositoryName, issueNumber);

// Retrieve the comment
var retrieved = await _issueCommentsClient.Get(context.RepositoryOwner, context.RepositoryName, commentId);

// Check the reactions
Assert.True(retrieved.Id > 0);
Assert.Equal(6, retrieved.Reactions.TotalCount);
Assert.Equal(1, retrieved.Reactions.Plus1);
Assert.Equal(1, retrieved.Reactions.Hooray);
Assert.Equal(1, retrieved.Reactions.Heart);
Assert.Equal(1, retrieved.Reactions.Laugh);
Assert.Equal(1, retrieved.Reactions.Confused);
Assert.Equal(1, retrieved.Reactions.Minus1);
}
}
}

public class TheGetAllForRepositoryMethod
{
readonly IGitHubClient _github;
readonly IIssueCommentsClient _issueCommentsClient;

const string owner = "octokit";
Expand All @@ -49,9 +80,9 @@ public class TheGetAllForRepositoryMethod

public TheGetAllForRepositoryMethod()
{
var github = Helper.GetAuthenticatedClient();
_github = Helper.GetAuthenticatedClient();

_issueCommentsClient = github.Issue.Comment;
_issueCommentsClient = _github.Issue.Comment;
}

[IntegrationTest]
Expand Down Expand Up @@ -181,10 +212,50 @@ public async Task ReturnsDistinctResultsBasedOnStartPageWithRepositoryId()
Assert.NotEqual(firstPageIssueComments[3].Id, secondPageIssueComments[3].Id);
Assert.NotEqual(firstPageIssueComments[4].Id, secondPageIssueComments[4].Id);
}

[IntegrationTest]
public async Task CanGetReactionPayload()
{
var numberToCreate = 2;
using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("IssueCommentsReactionTests")))
{
var commentIds = new List<int>();

// Create multiple test issues
for (int count = 1; count <= numberToCreate; count++)
{
var issueNumber = await HelperCreateIssue(context.RepositoryOwner, context.RepositoryName);

// Each with a comment with reactions
var commentId = await HelperCreateIssueCommentWithReactions(context.RepositoryOwner, context.RepositoryName, issueNumber);
commentIds.Add(commentId);
}
Assert.Equal(numberToCreate, commentIds.Count);

// Retrieve all issue comments for the repo
var issueComments = await _issueCommentsClient.GetAllForRepository(context.RepositoryOwner, context.RepositoryName);

// Check the reactions
foreach (var commentId in commentIds)
{
var retrieved = issueComments.FirstOrDefault(x => x.Id == commentId);

Assert.NotNull(retrieved);
Assert.Equal(6, retrieved.Reactions.TotalCount);
Assert.Equal(1, retrieved.Reactions.Plus1);
Assert.Equal(1, retrieved.Reactions.Hooray);
Assert.Equal(1, retrieved.Reactions.Heart);
Assert.Equal(1, retrieved.Reactions.Laugh);
Assert.Equal(1, retrieved.Reactions.Confused);
Assert.Equal(1, retrieved.Reactions.Minus1);
}
}
}
}

public class TheGetAllForIssueMethod
{
readonly IGitHubClient _github;
readonly IIssueCommentsClient _issueCommentsClient;

const string owner = "octokit";
Expand All @@ -194,9 +265,9 @@ public class TheGetAllForIssueMethod

public TheGetAllForIssueMethod()
{
var github = Helper.GetAuthenticatedClient();
_github = Helper.GetAuthenticatedClient();

_issueCommentsClient = github.Issue.Comment;
_issueCommentsClient = _github.Issue.Comment;
}

[IntegrationTest]
Expand Down Expand Up @@ -326,6 +397,45 @@ public async Task ReturnsDistinctResultsBasedOnStartPageWithRepositoryId()
Assert.NotEqual(firstPageIssueComments[3].Id, secondPageIssueComments[3].Id);
Assert.NotEqual(firstPageIssueComments[4].Id, secondPageIssueComments[4].Id);
}

[IntegrationTest]
public async Task CanGetReactionPayload()
{
var numberToCreate = 2;
using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("IssueCommentsReactionTests")))
{
var commentIds = new List<int>();

// Create a single test issue
var issueNumber = await HelperCreateIssue(context.RepositoryOwner, context.RepositoryName);

// With multiple comments with reactions
for (int count = 1; count <= numberToCreate; count++)
{
var commentId = await HelperCreateIssueCommentWithReactions(context.RepositoryOwner, context.RepositoryName, issueNumber);
commentIds.Add(commentId);
}
Assert.Equal(numberToCreate, commentIds.Count);

// Retrieve all comments for the issue
var issueComments = await _issueCommentsClient.GetAllForIssue(context.RepositoryOwner, context.RepositoryName, issueNumber);

// Check the reactions
foreach (var commentId in commentIds)
{
var retrieved = issueComments.FirstOrDefault(x => x.Id == commentId);

Assert.NotNull(retrieved);
Assert.Equal(6, retrieved.Reactions.TotalCount);
Assert.Equal(1, retrieved.Reactions.Plus1);
Assert.Equal(1, retrieved.Reactions.Hooray);
Assert.Equal(1, retrieved.Reactions.Heart);
Assert.Equal(1, retrieved.Reactions.Laugh);
Assert.Equal(1, retrieved.Reactions.Confused);
Assert.Equal(1, retrieved.Reactions.Minus1);
}
}
}
}

public class TheCreateMethod
Expand Down Expand Up @@ -472,4 +582,36 @@ public async Task DeleteIssueWithRepositoryId()
await Assert.ThrowsAsync<NotFoundException>(() => _issueCommentsClient.Get(_context.Repository.Id, comment.Id));
}
}

async static Task<int> HelperCreateIssue(string owner, string repo)
{
var github = Helper.GetAuthenticatedClient();

var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" };
var issue = await github.Issue.Create(owner, repo, newIssue);
Assert.NotNull(issue);

return issue.Number;
}

async static Task<int> HelperCreateIssueCommentWithReactions(string owner, string repo, int number)
{
var github = Helper.GetAuthenticatedClient();

var issueComment = await github.Issue.Comment.Create(owner, repo, number, "A test issue comment");
Assert.NotNull(issueComment);

foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType)))
{
var newReaction = new NewReaction(reactionType);

var reaction = await github.Reaction.IssueComment.Create(owner, repo, issueComment.Id, newReaction);

Assert.IsType<Reaction>(reaction);
Assert.Equal(reactionType, reaction.Content);
Assert.Equal(issueComment.User.Id, reaction.User.Id);
}

return issueComment.Id;
}
}
Loading