-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompanyLicenseControllerWithSystemLicense.cs
More file actions
64 lines (51 loc) · 2.72 KB
/
Copy pathCompanyLicenseControllerWithSystemLicense.cs
File metadata and controls
64 lines (51 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System.Net;
using Fossa.API.FunctionalTests.Seed;
using Fossa.API.Web;
using Fossa.Bridge.Services;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
namespace Fossa.API.FunctionalTests.ControllerApis;
public class CompanyLicenseControllerWithSystemLicense : IClassFixture<CustomWebApplicationFactory<DefaultWebModule>>, IAsyncLifetime
{
private readonly CustomWebApplicationFactory<DefaultWebModule> _factory;
public CompanyLicenseControllerWithSystemLicense(CustomWebApplicationFactory<DefaultWebModule> factory)
{
_factory = factory ?? throw new ArgumentNullException(nameof(factory));
}
[Fact]
public async Task CreateCompanyLicenseWithAdministratorAccessTokenAsync()
{
await _factory.SeedCompanyLicenseAsync("01JBV0GR968WJ25BKJVT8NDXEY.Tenant1.ADMIN1", 10, 4, 2, TestContext.Current.CancellationToken);
using var scope = _factory.Services.CreateScope();
var companyLicenseClient = scope.ServiceProvider.GetRequiredService<IClients>().CompanyLicenseClient;
var accessTokenContext = scope.ServiceProvider.GetRequiredService<IAccessTokenContext>();
accessTokenContext.SetAccessToken("01JA1ZJAWF27S0J8Z2VJE7673Y.Tenant1.User1");
var licenseResponseModel = (await companyLicenseClient.GetLicenseAsync(TestContext.Current.CancellationToken)).Unwrap();
licenseResponseModel.ShouldNotBeNull();
licenseResponseModel.Terms.ShouldNotBeNull();
licenseResponseModel.Terms.Licensor.ShouldNotBeNull();
licenseResponseModel.Terms.Licensee.ShouldNotBeNull();
licenseResponseModel.Entitlements.ShouldNotBeNull();
licenseResponseModel.Entitlements.MaximumBranchCount.ShouldBe(4);
licenseResponseModel.Entitlements.MaximumEmployeeCount.ShouldBe(10);
}
[Fact]
public async Task CreateCompanyLicenseWithUserAccessTokenAsync()
{
Func<Task> tryToCreateCompanyLicense = () => _factory.SeedCompanyLicenseAsync("01JBV0GR968WJ25BKJVT8NDXEY.Tenant2.User1", 4, 10, 2, TestContext.Current.CancellationToken);
await tryToCreateCompanyLicense.ShouldThrowAsync<HttpRequestException>();
}
public ValueTask DisposeAsync() => ValueTask.CompletedTask;
public async ValueTask InitializeAsync()
{
await _factory.SeedSystemLicenseAsync(TestContext.Current.CancellationToken).ConfigureAwait(false);
await _factory.SeedCompaniesAsync(TestContext.Current.CancellationToken).ConfigureAwait(false);
}
[Fact]
public async Task RetrieveCompanyLicenseWithoutAccessTokenAsync()
{
using var scope = _factory.Services.CreateScope();
var companyLicenseClient = scope.ServiceProvider.GetRequiredService<IClients>().CompanyLicenseClient;
(await companyLicenseClient.GetLicenseAsync(TestContext.Current.CancellationToken)).ShouldFailWith(HttpStatusCode.Unauthorized);
}
}