-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19dea6b
commit 58f67e9
Showing
4 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/tests/Fusion.Summary.Api.Tests/Helpers/ProjectHelpers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using FluentAssertions; | ||
using Fusion.Summary.Api.Controllers.ApiModels; | ||
using Fusion.Testing; | ||
|
||
namespace Fusion.Summary.Api.Tests.Helpers; | ||
|
||
public static class ProjectHelpers | ||
{ | ||
public static ApiProject GenerateProject(Guid? directorAzureUniqueId = null, Guid[]? additionalAdmins = null) | ||
{ | ||
var id = Guid.NewGuid(); | ||
return new ApiProject | ||
{ | ||
Id = id, | ||
Name = "Test Project - " + id, | ||
OrgProjectExternalId = Guid.NewGuid(), | ||
DirectorAzureUniqueId = directorAzureUniqueId, | ||
AssignedAdminsAzureUniqueId = additionalAdmins ?? [] | ||
}; | ||
} | ||
|
||
public static async Task<TestClientHttpResponse<ApiProject>> PutProjectAsync(this HttpClient client, Action<ApiProject>? setup = null) | ||
{ | ||
var project = GenerateProject(); | ||
setup?.Invoke(project); | ||
|
||
var response = await client.TestClientPutAsync<ApiProject>($"projects/{project.OrgProjectExternalId}", project); | ||
return response; | ||
} | ||
|
||
public static async Task<TestClientHttpResponse<ApiProject>> GetProjectAsync(this HttpClient client, | ||
string projectId) | ||
{ | ||
var response = await client.TestClientGetAsync<ApiProject>($"projects/{projectId}"); | ||
return response; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/tests/Fusion.Summary.Api.Tests/Helpers/WeeklyTaskOwnerReportHelpers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using Fusion.Summary.Api.Controllers.ApiModels; | ||
using Fusion.Summary.Api.Controllers.Requests; | ||
using Fusion.Testing; | ||
|
||
namespace Fusion.Summary.Api.Tests.Helpers; | ||
|
||
public static class WeeklyTaskOwnerReportHelpers | ||
{ | ||
public static async Task<TestClientHttpResponse<ApiCollection<ApiWeeklyTaskOwnerReport>>> | ||
GetWeeklyTaskOwnerReportsAsync( | ||
this HttpClient client, string projectId) | ||
{ | ||
var response = | ||
await client.TestClientGetAsync<ApiCollection<ApiWeeklyTaskOwnerReport>>( | ||
$"projects/{projectId}/task-owners-summary-reports/weekly"); | ||
|
||
return response; | ||
} | ||
|
||
public static async Task<TestClientHttpResponse<ApiWeeklyTaskOwnerReport>> PutWeeklyTaskOwnerReportAsync(this HttpClient client, | ||
string projectId, Action<PutWeeklyTaskOwnerReportRequest>? setup = null) | ||
{ | ||
var now = CreateDayOfWeek(DayOfWeek.Monday); | ||
var request = new PutWeeklyTaskOwnerReportRequest() | ||
{ | ||
PeriodStart = now, | ||
PeriodEnd = now.AddDays(7), | ||
ActionsAwaitingTaskOwnerAction = 1, | ||
PositionAllocationsEndingInNextThreeMonths = Enumerable.Range(1, 5).Select(i => new ApiPositionAllocationEnding | ||
{ | ||
PositionName = i.ToString(), | ||
PositionNameDetailed = i.ToString(), | ||
PositionAppliesTo = now.AddDays(20), | ||
PositionExternalId = i.ToString() | ||
}).ToArray(), | ||
AdminAccessExpiringInLessThanThreeMonths = Enumerable.Range(1, 5).Select(i => new ApiAdminAccessExpiring | ||
{ | ||
AzureUniqueId = Guid.NewGuid(), | ||
FullName = i.ToString(), | ||
Expires = now.AddDays(20) | ||
}).ToArray(), | ||
TBNPositionsStartingInLessThanThreeMonths = Enumerable.Range(6, 5).Select(i => new ApiTBNPositionStartingSoon | ||
{ | ||
PositionName = i.ToString(), | ||
PositionNameDetailed = i.ToString(), | ||
PositionAppliesFrom = now.AddDays(20), | ||
PositionExternalId = i.ToString() | ||
}).ToArray() | ||
}; | ||
|
||
setup?.Invoke(request); | ||
|
||
return await client.TestClientPutAsync<ApiWeeklyTaskOwnerReport>($"projects/{projectId}/task-owners-summary-reports/weekly", | ||
request); | ||
} | ||
|
||
private static DateTime CreateDayOfWeek(DayOfWeek dayOfWeek) | ||
{ | ||
var newDate = DateTime.UtcNow; | ||
|
||
var daysUntil = ((int)dayOfWeek - (int)newDate.DayOfWeek + 7) % 7; | ||
|
||
return newDate.AddDays(daysUntil); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/tests/Fusion.Summary.Api.Tests/IntegrationTests/ProjectTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using FluentAssertions; | ||
using Fusion.Summary.Api.Tests.Fixture; | ||
using Fusion.Summary.Api.Tests.Helpers; | ||
using Fusion.Summary.Api.Tests.IntegrationTests.Base; | ||
using Fusion.Testing; | ||
using Xunit.Abstractions; | ||
|
||
namespace Fusion.Summary.Api.Tests.IntegrationTests; | ||
|
||
[Collection(TestCollections.SUMMARY)] | ||
public class ProjectTests : TestBase | ||
{ | ||
private readonly SummaryApiFixture _fixture; | ||
private HttpClient _client; | ||
|
||
public ProjectTests(SummaryApiFixture fixture, ITestOutputHelper output) | ||
{ | ||
_fixture = fixture; | ||
_client = fixture.GetClient(); | ||
SetOutput(output); | ||
} | ||
|
||
[Fact] | ||
public async Task PutProject_Then_GetProject_ShouldBeSuccess() | ||
{ | ||
using var adminScope = _fixture.AdminScope(); | ||
var testUser = _fixture.Fusion.CreateUser().AsEmployee().AzureUniqueId!.Value; | ||
|
||
var externalId = Guid.NewGuid(); | ||
|
||
var response = await _client.PutProjectAsync(s => | ||
{ | ||
s.OrgProjectExternalId = externalId; | ||
s.DirectorAzureUniqueId = testUser; | ||
}); | ||
response.Should().BeSuccessfull(); | ||
|
||
var getResponse = await _client.GetProjectAsync(externalId.ToString()); | ||
getResponse.Should().BeSuccessfull(); | ||
getResponse.Value!.OrgProjectExternalId.Should().Be(externalId); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/tests/Fusion.Summary.Api.Tests/IntegrationTests/WeeklyTaskOwnerReportTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using FluentAssertions; | ||
using Fusion.Summary.Api.Tests.Fixture; | ||
using Fusion.Summary.Api.Tests.Helpers; | ||
using Fusion.Summary.Api.Tests.IntegrationTests.Base; | ||
using Fusion.Testing; | ||
using Xunit.Abstractions; | ||
|
||
namespace Fusion.Summary.Api.Tests.IntegrationTests; | ||
|
||
[Collection(TestCollections.SUMMARY)] | ||
public class WeeklyTaskOwnerReportTests : TestBase | ||
{ | ||
private readonly SummaryApiFixture _fixture; | ||
private HttpClient _client; | ||
|
||
public WeeklyTaskOwnerReportTests(SummaryApiFixture fixture, ITestOutputHelper output) | ||
{ | ||
_fixture = fixture; | ||
_client = _fixture.GetClient(); | ||
SetOutput(output); | ||
} | ||
|
||
|
||
[Fact] | ||
public async Task PutAndGetWeeklyTaskOwnerReport_ShouldReturnReport() | ||
{ | ||
using var adminScope = _fixture.AdminScope(); | ||
var testUser = _fixture.Fusion.CreateUser().AsEmployee().AzureUniqueId!.Value; | ||
|
||
var projectResponse = await _client.PutProjectAsync(s => { s.DirectorAzureUniqueId = testUser; }); | ||
projectResponse.Should().BeSuccessfull(); | ||
var projectExternalId = projectResponse.Value!.OrgProjectExternalId.ToString(); | ||
|
||
var response = await _client.PutWeeklyTaskOwnerReportAsync(projectExternalId); | ||
response.Should().BeSuccessfull(); | ||
|
||
var getResponse = await _client.GetWeeklyTaskOwnerReportsAsync(projectExternalId); | ||
getResponse.Should().BeSuccessfull(); | ||
getResponse.Value!.Items.Should().HaveCount(1); | ||
} | ||
|
||
[Fact] | ||
public async Task PutWeeklyTaskOwnerReport_WithInvalidPeriodDate_ShouldReturnBadRequest() | ||
{ | ||
using var adminScope = _fixture.AdminScope(); | ||
var testUser = _fixture.Fusion.CreateUser().AsEmployee().AzureUniqueId!.Value; | ||
|
||
var projectResponse = await _client.PutProjectAsync(s => { s.DirectorAzureUniqueId = testUser; }); | ||
projectResponse.Should().BeSuccessfull(); | ||
var project = projectResponse.Value!; | ||
|
||
var reportResponse = await _client.PutWeeklyTaskOwnerReportAsync(project.OrgProjectExternalId.ToString(), (report) => | ||
{ | ||
var nowDate = DateTime.UtcNow; | ||
if (nowDate.DayOfWeek == DayOfWeek.Monday) | ||
nowDate = nowDate.AddDays(1); | ||
report.PeriodStart = nowDate; | ||
}); | ||
|
||
reportResponse.Should().BeBadRequest(); | ||
} | ||
} |