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

Correctly deserialize CollaboratorPermissionResponse #2682

Merged
merged 1 commit into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 52 additions & 0 deletions Octokit.Tests/Models/CollaboratorPermissionResponseTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Octokit;
using Octokit.Internal;
using Xunit;

public class CollaboratorPermissionResponseTests
{
[Fact]
public void CanDeserialize()
{
const string json = @"{
""permission"": ""read"",
""user"": {
""login"": ""octocat"",
""id"": 583231,
""node_id"": ""MDQ6VXNlcjU4MzIzMQ=="",
""avatar_url"": ""https://avatars.githubusercontent.com/u/583231?v=4"",
""gravatar_id"": """",
""url"": ""https://api.github.com/users/octocat"",
""html_url"": ""https://github.com/octocat"",
""followers_url"": ""https://api.github.com/users/octocat/followers"",
""following_url"": ""https://api.github.com/users/octocat/following{/other_user}"",
""gists_url"": ""https://api.github.com/users/octocat/gists{/gist_id}"",
""starred_url"": ""https://api.github.com/users/octocat/starred{/owner}{/repo}"",
""subscriptions_url"": ""https://api.github.com/users/octocat/subscriptions"",
""organizations_url"": ""https://api.github.com/users/octocat/orgs"",
""repos_url"": ""https://api.github.com/users/octocat/repos"",
""events_url"": ""https://api.github.com/users/octocat/events{/privacy}"",
""received_events_url"": ""https://api.github.com/users/octocat/received_events"",
""type"": ""User"",
""site_admin"": false,
""permissions"": {
""admin"": false,
""maintain"": false,
""push"": false,
""triage"": false,
""pull"": true
},
""role_name"": ""read""
},
""role_name"": ""read""
}";

var actual = new SimpleJsonSerializer().Deserialize<CollaboratorPermissionResponse>(json);

Assert.Equal("read", actual.Permission);
Assert.Equal("octocat", actual.Collaborator.Login);
Assert.Equal(583231, actual.Collaborator.Id);
Assert.Equal("read", actual.RoleName);

Assert.Equal("Collaborator: 583231 Permission: read RoleName: read", actual.DebuggerDisplay);
}
}
2 changes: 2 additions & 0 deletions Octokit/Models/Response/CollaboratorPermissionResponse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using Octokit.Internal;

namespace Octokit
{
Expand All @@ -21,6 +22,7 @@ public CollaboratorPermissionResponse(string permission, string roleName, Collab

public string RoleName { get; private set; }

[Parameter(Key = "user")]
public Collaborator Collaborator { get; private set; }

internal string DebuggerDisplay => $"Collaborator: {Collaborator.Id} Permission: {Permission} RoleName: {RoleName}";
Expand Down