From 3e92a697b44642e69f9ae640f57450b8e7153c09 Mon Sep 17 00:00:00 2001 From: MareMare Date: Wed, 3 Jan 2024 07:12:19 +0900 Subject: [PATCH] [Fix]: The methods `GetAllForCurrentWithTimestamps` and `GetAllForUserWithTimestamps` now return timestamps. * Fix unit tests. * Fix integration tests. * Fix to use `AcceptHeaders.StarJson`. --------- Co-authored-by: Nick Floyd <139819+nickfloyd@users.noreply.github.com> --- .../Clients/StarredClientTests.cs | 8 ++++++++ Octokit.Tests/Clients/StarredClientTests.cs | 16 ++++++++-------- Octokit/Clients/StarredClient.cs | 8 ++++---- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/StarredClientTests.cs b/Octokit.Tests.Integration/Clients/StarredClientTests.cs index 4187d2c7..86175afe 100644 --- a/Octokit.Tests.Integration/Clients/StarredClientTests.cs +++ b/Octokit.Tests.Integration/Clients/StarredClientTests.cs @@ -167,6 +167,8 @@ namespace Octokit.Tests.Integration.Clients var repo = stars.FirstOrDefault(star => star.Repo.Owner.Login == _repositoryContext.RepositoryOwner && star.Repo.Name == _repositoryContext.RepositoryName); Assert.NotNull(repo); + Assert.NotEqual(DateTimeOffset.MinValue, repo.StarredAt); + Assert.NotNull(repo.Repo); } [IntegrationTest] @@ -232,6 +234,8 @@ namespace Octokit.Tests.Integration.Clients var repo = stars.FirstOrDefault(star => star.Repo.Owner.Login == _repositoryContext.RepositoryOwner && star.Repo.Name == _repositoryContext.RepositoryName); Assert.NotNull(repo); + Assert.NotEqual(DateTimeOffset.MinValue, repo.StarredAt); + Assert.NotNull(repo.Repo); for (int i = 1; i < stars.Count; i++) { @@ -456,6 +460,8 @@ namespace Octokit.Tests.Integration.Clients var star = stars.FirstOrDefault(repositoryStar => repositoryStar.Repo.Owner.Login == _repositoryContext.RepositoryOwner && repositoryStar.Repo.Name == _repositoryContext.RepositoryName); Assert.NotNull(star); + Assert.NotEqual(DateTimeOffset.MinValue, star.StarredAt); + Assert.NotNull(star.Repo); } [IntegrationTest] @@ -521,6 +527,8 @@ namespace Octokit.Tests.Integration.Clients var repo = stars.FirstOrDefault(repository => repository.Repo.Owner.Login == _repositoryContext.RepositoryOwner && repository.Repo.Name == _repositoryContext.RepositoryName); Assert.NotNull(repo); + Assert.NotEqual(DateTimeOffset.MinValue, repo.StarredAt); + Assert.NotNull(repo.Repo); for (int i = 1; i < stars.Count; i++) { diff --git a/Octokit.Tests/Clients/StarredClientTests.cs b/Octokit.Tests/Clients/StarredClientTests.cs index f49ddc41..daa13a28 100644 --- a/Octokit.Tests/Clients/StarredClientTests.cs +++ b/Octokit.Tests/Clients/StarredClientTests.cs @@ -99,7 +99,7 @@ namespace Octokit.Tests.Clients await client.GetAllForCurrentWithTimestamps(); - connection.Received().GetAll(endpoint, null, Args.ApiOptions); + connection.Received().GetAll(endpoint, null, AcceptHeaders.StarJson, Args.ApiOptions); } [Fact] @@ -118,7 +118,7 @@ namespace Octokit.Tests.Clients await client.GetAllForCurrentWithTimestamps(options); - connection.Received().GetAll(endpoint, null, options); + connection.Received().GetAll(endpoint, null, AcceptHeaders.StarJson, options); } [Fact] @@ -132,7 +132,7 @@ namespace Octokit.Tests.Clients await client.GetAllForCurrentWithTimestamps(request); - connection.Received().GetAll(endpoint, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc"), Args.ApiOptions); + connection.Received().GetAll(endpoint, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc"), AcceptHeaders.StarJson, Args.ApiOptions); } [Fact] @@ -153,7 +153,7 @@ namespace Octokit.Tests.Clients await client.GetAllForCurrentWithTimestamps(request, options); - connection.Received().GetAll(endpoint, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc"), options); + connection.Received().GetAll(endpoint, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc"), AcceptHeaders.StarJson, options); } [Fact] @@ -250,7 +250,7 @@ namespace Octokit.Tests.Clients await client.GetAllForUserWithTimestamps("banana"); - connection.Received().GetAll(endpoint, null, Args.ApiOptions); + connection.Received().GetAll(endpoint, null, AcceptHeaders.StarJson, Args.ApiOptions); } [Fact] @@ -269,7 +269,7 @@ namespace Octokit.Tests.Clients await client.GetAllForUserWithTimestamps("banana", options); - connection.Received().GetAll(endpoint, null, options); + connection.Received().GetAll(endpoint, null, AcceptHeaders.StarJson, options); } [Fact] @@ -283,7 +283,7 @@ namespace Octokit.Tests.Clients await client.GetAllForUserWithTimestamps("banana", starredRequest); - connection.Received().GetAll(endpoint, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc"), Args.ApiOptions); + connection.Received().GetAll(endpoint, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc"), AcceptHeaders.StarJson, Args.ApiOptions); } [Fact] @@ -304,7 +304,7 @@ namespace Octokit.Tests.Clients await client.GetAllForUserWithTimestamps("banana", starredRequest, options); - connection.Received().GetAll(endpoint, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc"), options); + connection.Received().GetAll(endpoint, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc"), AcceptHeaders.StarJson, options); } [Fact] diff --git a/Octokit/Clients/StarredClient.cs b/Octokit/Clients/StarredClient.cs index 6a4d81e4..5aaf40e4 100644 --- a/Octokit/Clients/StarredClient.cs +++ b/Octokit/Clients/StarredClient.cs @@ -177,7 +177,7 @@ namespace Octokit { Ensure.ArgumentNotNull(options, nameof(options)); - return ApiConnection.GetAll(ApiUrls.Starred(), null, options); + return ApiConnection.GetAll(ApiUrls.Starred(), null, AcceptHeaders.StarJson, options); } /// @@ -237,7 +237,7 @@ namespace Octokit Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(options, nameof(options)); - return ApiConnection.GetAll(ApiUrls.Starred(), request.ToParametersDictionary(), options); + return ApiConnection.GetAll(ApiUrls.Starred(), request.ToParametersDictionary(), AcceptHeaders.StarJson, options); } /// @@ -293,7 +293,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(user, nameof(user)); Ensure.ArgumentNotNull(options, nameof(options)); - return ApiConnection.GetAll(ApiUrls.StarredByUser(user), null, options); + return ApiConnection.GetAll(ApiUrls.StarredByUser(user), null, AcceptHeaders.StarJson, options); } /// @@ -359,7 +359,7 @@ namespace Octokit Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(options, nameof(options)); - return ApiConnection.GetAll(ApiUrls.StarredByUser(user), request.ToParametersDictionary(), options); + return ApiConnection.GetAll(ApiUrls.StarredByUser(user), request.ToParametersDictionary(), AcceptHeaders.StarJson, options); } ///