Skip to content

Commit 3932b02

Browse files
test(audience-sdk): centralise HTTP test response body and exception fixtures
HttpTransportTests had inline literals for the malformed-body diagnostic ("not-json"), the empty JSON object body ("{}"), and the exception messages thrown by MockHandler factories ("connection refused", "Request timed out", "simulated"). Adds five file-local consts (MalformedResponseBody, EmptyJsonObjectBody, ConnectionRefusedMessage, RequestTimedOutMessage, SimulatedCancellationMessage) at the top of the fixture and migrates six call sites. The empty body "" is left inline since "the body is truly empty" carries the meaning at the call site. NUnit assertions never check the exception messages, but pinning the "what failure was simulated" intent keeps the fixture's catalogue of network failure modes visible in one place. Per the user's "everything random goes in a constant" stance. Follow-up to SDK-272 (centralisation of duplicated literals).
1 parent 13139c4 commit 3932b02

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

src/Packages/Audience/Tests/Runtime/Transport/HttpTransportTests.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ namespace Immutable.Audience.Tests
1717
[TestFixture]
1818
internal class HttpTransportTests
1919
{
20+
// Response body fixtures.
21+
private const string MalformedResponseBody = "not-json";
22+
private const string EmptyJsonObjectBody = "{}";
23+
24+
// Exception messages thrown by MockHandler factories.
25+
private const string ConnectionRefusedMessage = "connection refused";
26+
private const string RequestTimedOutMessage = "Request timed out";
27+
private const string SimulatedCancellationMessage = "simulated";
28+
2029
private string _testDir = null!;
2130
private DiskStore _store = null!;
2231

@@ -176,7 +185,7 @@ public async Task SendBatchAsync_BaseUrlOverride_WinsOverKeyPrefix()
176185
[Test]
177186
public async Task SendBatchAsync_EmptyQueue_ReturnsFalse()
178187
{
179-
var handler = new MockHandler(HttpStatusCode.OK, "{}");
188+
var handler = new MockHandler(HttpStatusCode.OK, EmptyJsonObjectBody);
180189
using var transport = new HttpTransport(_store, TestDefaults.PublishableKey, handler: handler);
181190

182191
var sent = await transport.SendBatchAsync();
@@ -359,7 +368,7 @@ public async Task SendBatchAsync_200_MalformedBody_TreatsAsZeroRejected()
359368
// Malformed diagnostic body must not block the success path.
360369
_store.Write(WireFixture.Track((MessageFields.EventName, TestEventNames.PlaceholderA)));
361370

362-
var handler = new MockHandler(HttpStatusCode.OK, "not-json");
371+
var handler = new MockHandler(HttpStatusCode.OK, MalformedResponseBody);
363372
AudienceError? reportedError = null;
364373
using var transport = new HttpTransport(_store, TestDefaults.PublishableKey,
365374
onError: e => reportedError = e, handler: handler);
@@ -491,7 +500,7 @@ public async Task SendBatchAsync_NetworkError_KeepsFilesAndBacksOff()
491500
{
492501
_store.Write(WireFixture.Track());
493502

494-
var handler = new MockHandler(() => throw new HttpRequestException("connection refused"));
503+
var handler = new MockHandler(() => throw new HttpRequestException(ConnectionRefusedMessage));
495504
AudienceError? reportedError = null;
496505
using var transport = new HttpTransport(_store, TestDefaults.PublishableKey,
497506
onError: e => reportedError = e, handler: handler);
@@ -514,7 +523,7 @@ public async Task SendBatchAsync_HttpClientTimeout_TreatedAsNetworkError()
514523
// NetworkError path.
515524
_store.Write(WireFixture.Track());
516525

517-
var handler = new MockHandler(() => throw new TaskCanceledException("Request timed out"));
526+
var handler = new MockHandler(() => throw new TaskCanceledException(RequestTimedOutMessage));
518527
AudienceError? reportedError = null;
519528
using var transport = new HttpTransport(_store, TestDefaults.PublishableKey,
520529
onError: e => reportedError = e, handler: handler);
@@ -540,7 +549,7 @@ public async Task SendBatchAsync_CallerCancelled_Throws_DoesNotDeleteOrRecordFai
540549
// forever: nothing ever drains, nothing ever throws.
541550
_store.Write(WireFixture.Track());
542551

543-
var handler = new MockHandler(() => throw new OperationCanceledException("simulated"));
552+
var handler = new MockHandler(() => throw new OperationCanceledException(SimulatedCancellationMessage));
544553
AudienceError? reportedError = null;
545554
using var transport = new HttpTransport(_store, TestDefaults.PublishableKey,
546555
onError: e => reportedError = e, handler: handler);

0 commit comments

Comments
 (0)