Files
octokit.net/Octokit.Tests/Reactive/ObservableRepositorySecretsClientTests.cs
Keegan Campbell 131ba87e3f Replay #2221: Implement GitHub Actions Secrets API for both Organization and Repository (#2598)
* created the interface and models for the repository secrets client

* created a repository actions client to sit between repository and secrets for future extensibility

* created the repository secret client and supporting objects to enable data transfer

* created object for create or update secret body and made fixes to pass unit tests

* created repository action unit tests

* created unit tests for RepositorySecretsClient

* removed set from secrets interface

* fixed docs and added observable actions client

* added Actions to repository client

* created IObservable repository secrets client

* fixed property in wrong interface
fixed wrong Ctor unit test

* created repository decrets reactive tests and clients

* created organization actions and scerets classes and made them available through the oprganizations client

* fixed intellisense text

* removed uneeded getall call after return type change

* created organization secret client and classes to support it

* created the observable org secrets client and fixed a typo in a method name

* added more ensure checks

* removed unused xml doc setting

* created the unit tests for the organization secrets client
fixed broken unit test for repository secrets client

* created observable organization actions and secrets client unit tests

* added sodium.core to the integration tests to test secret creation

* fixed keyid type

* added actions client integration test classes (empty since the class currently doesn't have any native methods)

* fixed deserialization issue

* changed property name for deserialization issues

* added doc for repoid on orginzation secrets url generator

* created integration tests for repository and organization secrets

* changed how return occurs for setting list of repos for secret

* fixed some names and removed reset org name

* created integration tests for observable org secrets client

* removed  default org value

* created the integration tests for the observable repository secrets client

* removed default owner project value

* fixed unit tests

* Update links to new docs site

* Update doc links to new docs site

* Update docs links to new docs site

* Fix doc link to point to new docs site

* Update links to new docs site

* Update doc links to new docs site

* Update docs links

* Update docs

* Update docs

* Update doc links

* Update docs

* Update doc links

* Update doc links

* Update doc links

* updated documentation links in actions and secrets clients

* Update Octokit/Models/Response/SecretsPublicKey.cs

Removing line for consistency.

Co-authored-by: Thomas Hughes <iamhughes@github.com>

* Update Octokit/Models/Response/RepositorySecret.cs

Removing line for consistency.

Co-authored-by: Thomas Hughes <iamhughes@github.com>

* set default owner and repo

* switched to using the Helper.Organization from a ORG constant set at the top of the file

* swapped out variable at top of file for the Helper.Organization property

* switched to helper method to create new repositories

* Protected setters --> private setters in response models

* RepositorySecret needs protected setters

Co-authored-by: Mike Tolly <mike.tolly@takeda.com>
Co-authored-by: Thomas Hughes <iamhughes@github.com>
Co-authored-by: mptolly-takeda <61791994+mptolly-takeda@users.noreply.github.com>
2022-10-20 14:59:31 -07:00

171 lines
7.5 KiB
C#

using NSubstitute;
using Octokit.Reactive;
using System;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using System.Threading.Tasks;
using Xunit;
namespace Octokit.Tests.Reactive
{
public class ObservableRepositorySecretsClientTests
{
public class TheCtor
{
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new ObservableRepositorySecretsClient(null));
}
}
public class GetPublicKeyMethod
{
[Fact]
public async Task RequestsTheCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableRepositorySecretsClient(gitHubClient);
await client.GetPublicKey("owner", "repo");
gitHubClient.Received().Repository.Actions.Secrets.GetPublicKey("owner", "repo");
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new ObservableRepositorySecretsClient(Substitute.For<IGitHubClient>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetPublicKey(null, "repo").ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetPublicKey("owner", null).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.GetPublicKey("", "repo").ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.GetPublicKey("owner", "").ToTask());
}
}
public class GetAllMethod
{
[Fact]
public async Task RequestsTheCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableRepositorySecretsClient(gitHubClient);
await client.GetAll("owner", "repo");
gitHubClient.Received().Repository.Actions.Secrets.GetAll("owner", "repo");
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new ObservableRepositorySecretsClient(Substitute.For<IGitHubClient>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null, "repo").ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", null).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "repo").ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", "").ToTask());
}
}
public class GetMethod
{
[Fact]
public async Task RequestsTheCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableRepositorySecretsClient(gitHubClient);
await client.Get("owner", "repo","secret");
gitHubClient.Received().Repository.Actions.Secrets.Get("owner", "repo", "secret");
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new ObservableRepositorySecretsClient(Substitute.For<IGitHubClient>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "repo", "secret").ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", null, "secret").ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", "repo", null).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("", "repo", "secret").ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("owner", "", "secret").ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("owner", "repo", "").ToTask());
}
}
public class CreateOrUpdateMethod
{
[Fact]
public async Task PostsTheCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableRepositorySecretsClient(gitHubClient);
var upsert = new UpsertRepositorySecret
{
EncryptedValue = "encryptedValue",
KeyId = "keyId"
};
await client.CreateOrUpdate("owner", "repo", "secret", upsert);
gitHubClient.Received().Repository.Actions.Secrets.CreateOrUpdate("owner", "repo", "secret", upsert);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new ObservableRepositorySecretsClient(Substitute.For<IGitHubClient>());
var upsertSecret = new UpsertRepositorySecret
{
EncryptedValue = "encryptedValue",
KeyId = "keyId"
};
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate(null, "repo", "secret", upsertSecret).ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate("owner", null, "secret", upsertSecret).ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate("owner", "repo", null, upsertSecret).ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate("owner", "repo", "secret", null).ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate("owner", "repo", "secret", new UpsertRepositorySecret()).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.CreateOrUpdate("", "repo", "secret", upsertSecret).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.CreateOrUpdate("owner", "", "secret", upsertSecret).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.CreateOrUpdate("owner", "repo", "", upsertSecret).ToTask());
}
}
public class DeleteMethod
{
[Fact]
public async Task DeletesTheCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableRepositorySecretsClient(gitHubClient);
await client.Delete("owner", "repo", "secret");
gitHubClient.Received().Repository.Actions.Secrets.Delete("owner", "repo", "secret");
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new ObservableRepositorySecretsClient(Substitute.For<IGitHubClient>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Delete(null, "repo", "secret").ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Delete("owner", null, "secret").ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Delete("owner", "repo", null).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.Delete("", "repo", "secret").ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.Delete("owner", "", "secret").ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.Delete("owner", "repo", "").ToTask());
}
}
}
}