Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions PPMTool.Tests/API/BaseApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public static HttpClient GetClientAsManager()
return client;
}

[OneTimeSetUp]
public virtual void OneTimeSetup()
{
SetupForAPI();
}

public void SetupForAPI()
{
// Get the API key to use from the database
Expand Down Expand Up @@ -80,5 +86,20 @@ public void SetupForAPI()
throw new Exception("No valid API keys found for a manager with a report in the database. Please create one for testing.");
}
}

/// <summary>
/// Gets the start date for a date range query (one month ago).
/// </summary>
protected static string GetStartDate() => DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd");

/// <summary>
/// Gets the end date for a date range query (today).
/// </summary>
protected static string GetEndDate() => DateTime.Now.ToString("yyyy-MM-dd");

/// <summary>
/// Gets the current year for year-based queries.
/// </summary>
protected static int GetCurrentYear() => DateTime.Now.Year;
}
}
26 changes: 26 additions & 0 deletions PPMTool.Tests/API/LeaveBookings/EndpointOKTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-FileCopyrightText: 2026 University of Manchester
//
// SPDX-License-Identifier: apache-2.0

namespace PPMTool.Tests.API.LeaveBookings
{
[TestFixture]
public class EndpointOKTests : BaseApiTest
{
[Test]
public async Task GetStaffBookingsForYearShouldReturnOKOrErrorDependingOnDatabaseAvailability()
{
using (var client = GetClientAsManager())
{
var response = await client.GetAsync($"/leavebookings/getForSelfAndStaff?year={GetCurrentYear()}");
// This endpoint may return 500 if the Leave Bookings database is not available
// We just verify that the endpoint is accessible and returns a valid response
Assert.That(
response.StatusCode == System.Net.HttpStatusCode.OK ||
response.StatusCode == System.Net.HttpStatusCode.InternalServerError ||
response.StatusCode == System.Net.HttpStatusCode.BadRequest
);
}
}
}
}
22 changes: 21 additions & 1 deletion PPMTool.Tests/API/Skills/EndpointOKTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,25 @@ public async Task GetAllSkillsShouldReturnOK()
Assert.That(response.IsSuccessStatusCode);
}
}

[Test]
public async Task GetAllSkillsForPersonShouldReturnOK()
{
using (var client = GetClientAsManager())
{
var response = await client.GetAsync("/skills/getAllForPerson");
Assert.That(response.IsSuccessStatusCode);
}
}

[Test]
public async Task GetAllSkillsGroupedShouldReturnOK()
{
using (var client = GetClientAsManager())
{
var response = await client.GetAsync("/skills/getAllGrouped");
Assert.That(response.IsSuccessStatusCode);
}
}
}
}
}
21 changes: 20 additions & 1 deletion PPMTool.Tests/API/Timesheets/EndpointOKTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,24 @@ namespace PPMTool.Tests.API.Timesheets
[TestFixture]
public class EndpointOKTests : BaseApiTest
{
[Test]
public async Task GetTimesheetEntriesForPersonForDateRangeShouldReturnOK()
{
using (var client = GetClientAsManager())
{
var response = await client.GetAsync($"/timesheets/getEntries?startDate={GetStartDate()}&endDate={GetEndDate()}");
Assert.That(response.IsSuccessStatusCode);
}
}

[Test]
public async Task GetTimesheetBookingsByCodeAndTaskShouldReturnOK()
{
using (var client = GetClientAsManager())
{
var response = await client.GetAsync($"/timesheets/getByCodeTask?startDate={GetStartDate()}&endDate={GetEndDate()}");
Assert.That(response.IsSuccessStatusCode);
}
}
}
}
}
38 changes: 38 additions & 0 deletions PPMTool.Tests/API/WorkloadModelAnalysis/EndpointOKTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-FileCopyrightText: 2026 University of Manchester
//
// SPDX-License-Identifier: apache-2.0

namespace PPMTool.Tests.API.WorkloadModelAnalysis
{
[TestFixture]
public class EndpointOKTests : BaseApiTest
{
[Test]
public async Task GetWorkloadAnalysisDataShouldReturnOK()
{
using (var client = GetClientAsManager())
{
// Query requires personNames parameter
// Use empty string to get data for the API key owner by default
var response = await client.GetAsync($"/wlm/getAnalysis?personNames=&startDate={GetStartDate()}&endDate={GetEndDate()}");

// The endpoint can return various status codes depending on parameters:
// 200 OK if successful
// 400 Bad Request if parameters are invalid
// We verify the endpoint is accessible and returns a valid response
Assert.That(response.IsSuccessStatusCode || response.StatusCode == System.Net.HttpStatusCode.BadRequest);
}
}

[Test]
public async Task GetWorkloadAnalysisDataWithComparisonShouldReturnOK()
{
using (var client = GetClientAsManager())
{
var response = await client.GetAsync($"/wlm/getAnalysis?personNames=&startDate={GetStartDate()}&endDate={GetEndDate()}&compareToWLM=true&normalisedByTotalHours=true");

Assert.That(response.IsSuccessStatusCode || response.StatusCode == System.Net.HttpStatusCode.BadRequest);
}
}
}
}
Loading
Loading