Files
speckle-sharp-sdk/tests/Speckle.Core.Tests.Integration/Api/GraphQL/Resources/ProjectResourceExceptionalTests.cs
T
Adam Hathcock 200b84f49a Main to dev (#18)
* Add Instances base (#6)

* Use Uri for checks in GetAccounts function (#8)

* Add integration and perf tests to sln (#9)

* Remove perf tests (#10)

* remove perf tests

* do all unit tests

* Code coverage (#11)

* code coverage

* enable codecov for GA

* Update README.md

* Update coverage and dependencies (#12)

* Update coverage and dependencies

* fmt

* add codecov config

* merge DUI3/Alpha into sdk (#13)

* merge DUI3/Alpha into sdk

* formatting

* Merge Objects dui3/alpha -> dev (#14)

* merge DUI3/Alpha into sdk

* formatting

* Objects changes

* Objects tests

* Unit test project

* update codecov to be less intrusive (#15)

* update codecov to be less intrusive

* fix codecov yaml

* add coverage exclusion

* Merge sharp `dui3/alpha` -> sdk `main` (#16)

* Merge

* csharpier format

* Fixed polysharp issues

* Integration Tests

* Fixes

* Some nullability fixes (#17)

* add coverage exclusion

* fix some tests and fix nullability errors

---------

Co-authored-by: Oğuzhan Koral <45078678+oguzhankoral@users.noreply.github.com>
Co-authored-by: Jedd Morgan <45512892+JR-Morgan@users.noreply.github.com>
2024-07-09 13:56:03 +01:00

114 lines
3.6 KiB
C#

using Speckle.Core.Api;
using Speckle.Core.Api.GraphQL;
using Speckle.Core.Api.GraphQL.Enums;
using Speckle.Core.Api.GraphQL.Inputs;
using Speckle.Core.Api.GraphQL.Models;
using Speckle.Core.Api.GraphQL.Resources;
namespace Speckle.Core.Tests.Integration.API.GraphQL.Resources;
[TestOf(typeof(ProjectResource))]
public class ProjectResourceExceptionalTests
{
private Client _testUser,
_secondUser,
_unauthedUser;
private Project _testProject;
private ProjectResource Sut => _testUser.Project;
[OneTimeSetUp]
public async Task Setup()
{
_testUser = await Fixtures.SeedUserWithClient();
_secondUser = await Fixtures.SeedUserWithClient();
_unauthedUser = Fixtures.Unauthed;
_testProject = await _testUser.Project.Create(new("test project123", "desc", null));
}
//We want to check the following cases
// 1. User lacks permissions (without auth)
// 2. Target (Project or user) doesn't exist)
// 3. Cancellation
// 4. Server doesn't exist (is down)
//There's got to be a smarter way to parametrise these...
[Test]
public void ProjectCreate_WithoutAuth()
{
ProjectCreateInput input =
new("The best project", "The best description for the best project", ProjectVisibility.Private);
Assert.ThrowsAsync<SpeckleGraphQLForbiddenException>(async () => await _unauthedUser.Project.Create(input));
}
[Test]
public async Task ProjectGet_WithoutAuth()
{
ProjectCreateInput input = new("Private Stream", "A very private stream", ProjectVisibility.Private);
Project privateStream = await Sut.Create(input);
Assert.ThrowsAsync<SpeckleGraphQLForbiddenException>(async () => await _unauthedUser.Project.Get(privateStream.id));
}
[Test]
public void ProjectGet_NonExistentProject()
{
Assert.ThrowsAsync<SpeckleGraphQLStreamNotFoundException>(async () => await Sut.Get("NonExistentProject"));
}
[Test]
public void ProjectUpdate_NonExistentProject()
{
Assert.ThrowsAsync<SpeckleGraphQLForbiddenException>(
async () => _ = await Sut.Update(new("NonExistentProject", "My new name"))
);
}
[Test]
public void ProjectUpdate_NoAuth()
{
Assert.ThrowsAsync<SpeckleGraphQLForbiddenException>(
async () => _ = await _unauthedUser.Project.Update(new(_testProject.id, "My new name"))
);
}
[Test]
[TestCase(StreamRoles.STREAM_OWNER)]
[TestCase(StreamRoles.STREAM_CONTRIBUTOR)]
[TestCase(StreamRoles.STREAM_REVIEWER)]
[TestCase(StreamRoles.REVOKE)]
public void ProjectUpdateRole_NonExistentProject(string newRole)
{
ProjectUpdateRoleInput input = new(_secondUser.Account.id, "NonExistentProject", newRole);
Assert.ThrowsAsync<SpeckleGraphQLForbiddenException>(async () => await Sut.UpdateRole(input));
}
[Test]
[TestCase(StreamRoles.STREAM_OWNER)]
[TestCase(StreamRoles.STREAM_CONTRIBUTOR)]
[TestCase(StreamRoles.STREAM_REVIEWER)]
[TestCase(StreamRoles.REVOKE)]
public void ProjectUpdateRole_NonAuth(string newRole)
{
ProjectUpdateRoleInput input = new(_secondUser.Account.id, "NonExistentProject", newRole);
Assert.ThrowsAsync<SpeckleGraphQLForbiddenException>(async () => await _unauthedUser.Project.UpdateRole(input));
}
[Test]
public async Task ProjectDelete_NonExistentProject()
{
bool response = await Sut.Delete(_testProject.id);
Assert.That(response, Is.True);
Assert.ThrowsAsync<SpeckleGraphQLStreamNotFoundException>(async () => _ = await Sut.Get(_testProject.id)); //TODO: Exception types
}
[Test]
public void ProjectInvites_NoAuth()
{
Assert.ThrowsAsync<SpeckleGraphQLException>(async () => await Fixtures.Unauthed.ActiveUser.ProjectInvites());
}
}