fix(esg): JSON-serialise non-scalar GET/DELETE query parameters (review 2026-10-21 05/O2)

This commit is contained in:
Joseph Doherty
2026-10-22 08:32:41 -04:00
parent e93af5a21f
commit ee8be8001e
2 changed files with 55 additions and 1 deletions
@@ -782,6 +782,35 @@ public class ExternalSystemClientTests : IDisposable
Assert.Contains("page=2", uri);
}
/// <summary>Verifies that non-scalar GET parameters are JSON-serialised rather than rendered as CLR type names.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task Call_GetWithNonScalarParameters_JsonSerialisesThem()
{
// Review 2026-10-21 05/O2: new[]{1,2,3}.ToString() is "System.Int32[]".
var system = new ExternalSystemDefinition("TestAPI", "https://api.example.com", "none") { Id = 1 };
var method = new ExternalSystemMethod("search", "GET", "/search") { Id = 1, ExternalSystemDefinitionId = 1 };
StubResolution(system, method);
var handler = new RequestCapturingHandler(HttpStatusCode.OK, "{}");
_httpClientFactory.CreateClient(Arg.Any<string>()).Returns(new HttpClient(handler));
var client = new ExternalSystemClient(
_httpClientFactory, _repository, NullLogger<ExternalSystemClient>.Instance);
await client.CallAsync("TestAPI", "search", new Dictionary<string, object?>
{
["ids"] = new[] { 1, 2, 3 },
["f"] = new Dictionary<string, object?> { ["a"] = 1 },
["n"] = 7,
});
var uri = handler.LastUri!.AbsoluteUri;
Assert.Contains("ids=" + Uri.EscapeDataString("[1,2,3]"), uri);
Assert.Contains("f=" + Uri.EscapeDataString("{\"a\":1}"), uri);
Assert.Contains("n=7", uri);
Assert.DoesNotContain("System.", uri);
}
/// <summary>Verifies that a GET call whose parameters are all null does not append a trailing question mark.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]