using System.Net;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using Azaion.Missions.E2E.Fixtures;
using Azaion.Missions.E2E.Helpers;
using Xunit;
namespace Azaion.Missions.E2E.Tests.Missions;
///
/// FT-N-04 (carry-forward 400 for bogus VehicleId) and FT-N-05 (GET 404).
/// FT-N-06 (cascade short-circuit) lives in
/// because it manipulates Postgres logging and owns its own collection.
/// Traces: AC-2.2 (carry-forward), AC-2.4 / AC-8.2.
///
[Collection("Missions")]
[Trait("Category", "Blackbox")]
[Trait("db_access", "seed-or-assert-only")]
public sealed class NegativeTests : TestBase, IClassFixture
{
[Fact]
[Trait("Traces", "AC-2.2")]
[Trait("max_ms", "2000")]
[Trait("carry_forward", "AC-2.2")]
public async Task FT_N_04_create_mission_with_bogus_vehicle_id_returns_400_today()
{
// CARRY-FORWARD: spec wants 404 (results_report.md row 2.2 carry-forward).
// Today the SUT throws ArgumentException → ErrorHandlingMiddleware maps
// to 400. Flip to 404 expectation when the divergence is closed.
// Arrange
DbResetFixture.ResetDatabase(TestEnvironment.DbSideChannel);
var token = await Tokens.MintDefaultAsync();
var bogusVehicleId = Guid.NewGuid();
// Act
using var http = new HttpRequestMessage(HttpMethod.Post, "/missions")
{
Content = JsonContent.Create(new
{
Name = "x",
VehicleId = bogusVehicleId,
CreatedDate = (DateTime?)null
})
};
http.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token.Jwt);
using var response = await Missions.SendAsync(http);
// Assert
await HttpAssertions.AssertProblemEnvelopeAsync(response, HttpStatusCode.BadRequest)
;
var missionsRows = DbAssertions.TableRowCount("missions");
Assert.Equal(0L, missionsRows);
}
[Fact]
[Trait("Traces", "AC-2.4,AC-8.2")]
[Trait("max_ms", "2000")]
public async Task FT_N_05_get_mission_returns_404_with_problem_envelope()
{
// Arrange
DbResetFixture.ResetDatabase(TestEnvironment.DbSideChannel);
var token = await Tokens.MintDefaultAsync();
var randomId = Guid.NewGuid();
// Act
using var http = new HttpRequestMessage(HttpMethod.Get, $"/missions/{randomId}");
http.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token.Jwt);
using var response = await Missions.SendAsync(http);
// Assert
await HttpAssertions.AssertProblemEnvelopeAsync(response, HttpStatusCode.NotFound)
;
}
}