Skip to content

Commit f974d27

Browse files
test(audience-sdk): centralise SessionTests sabotage message and DiskStoreTests inline JSON keys
SessionTests had "track explode" inline four times as the InvalidOperationException message thrown by ThrowingTrack delegates across four session lifecycle scenarios. Adds a TrackExplodeMessage file-local const at the top of the fixture and migrates all four. DiskStoreTests built a Purchase-shaped JSON payload by hand-rolling the wire format with inline keys ("type", "eventName", "anonymousId", "userId", "properties", "currency", "value") and inline values ("track", "purchase", "USD", "a"). Replaces those with the SDK's existing constants (MessageFields.*, MessageTypes.Track, EventNames.Purchase, EventPropertyKeys.Currency / .Value) and the TestFixtures fixtures already centralised (UsdCurrency, TestEventNames.PlaceholderA). The "u" userId placeholder is left inline; centralising a single one-char placeholder would add more noise than it removes. Per the user's "everything random goes in a constant" stance. Follow-up to SDK-272 (centralisation of duplicated literals).
1 parent 13793cb commit f974d27

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/Packages/Audience/Tests/Runtime/Core/SessionTests.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ namespace Immutable.Audience.Tests
1010
[TestFixture]
1111
internal class SessionTests
1212
{
13+
// Exception thrown by the ThrowingTrack sabotage delegate across four scenarios.
14+
private const string TrackExplodeMessage = "track explode";
15+
1316
private List<(string name, Dictionary<string, object> props)> _events;
1417

1518
[SetUp]
@@ -546,7 +549,7 @@ public void OnHeartbeat_TrackCallbackThrows_DoesNotEscape()
546549
void ThrowingTrack(string name, Dictionary<string, object> props)
547550
{
548551
if (name == EventNames.SessionHeartbeat)
549-
throw new InvalidOperationException("track explode");
552+
throw new InvalidOperationException(TrackExplodeMessage);
550553
}
551554

552555
using var session = new Session(ThrowingTrack);
@@ -581,7 +584,7 @@ public void Start_TrackCallbackThrows_DoesNotEscape()
581584
void ThrowingTrack(string name, Dictionary<string, object> props)
582585
{
583586
if (name == EventNames.SessionStart)
584-
throw new InvalidOperationException("track explode");
587+
throw new InvalidOperationException(TrackExplodeMessage);
585588
}
586589

587590
using var session = new Session(ThrowingTrack);
@@ -616,7 +619,7 @@ public void End_TrackCallbackThrows_DoesNotEscape()
616619
void ThrowingTrack(string name, Dictionary<string, object> props)
617620
{
618621
if (name == EventNames.SessionEnd)
619-
throw new InvalidOperationException("track explode");
622+
throw new InvalidOperationException(TrackExplodeMessage);
620623
}
621624

622625
using var session = new Session(ThrowingTrack);
@@ -652,7 +655,7 @@ public void SafeTrack_LogWriterThrows_DoesNotEscape()
652655
void ThrowingTrack(string name, Dictionary<string, object> props)
653656
{
654657
if (name == EventNames.SessionHeartbeat)
655-
throw new InvalidOperationException("track explode");
658+
throw new InvalidOperationException(TrackExplodeMessage);
656659
}
657660

658661
using var session = new Session(ThrowingTrack);

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,13 @@ public void ApplyAnonymousDowngrade_PurchaseValue_RoundsTripsExactlyForRealistic
207207
TearDown();
208208
SetUp();
209209

210-
var json = "{\"type\":\"track\",\"eventName\":\"purchase\",\"anonymousId\":\"a\",\"userId\":\"u\","
211-
+ "\"properties\":{\"currency\":\"USD\",\"value\":" + amount + "}}";
210+
var json = $"{{\"{MessageFields.Type}\":\"{MessageTypes.Track}\","
211+
+ $"\"{MessageFields.EventName}\":\"{EventNames.Purchase}\","
212+
+ $"\"{MessageFields.AnonymousId}\":\"{TestEventNames.PlaceholderA}\","
213+
+ $"\"{MessageFields.UserId}\":\"u\","
214+
+ $"\"{MessageFields.Properties}\":{{"
215+
+ $"\"{EventPropertyKeys.Currency}\":\"{TestFixtures.UsdCurrency}\","
216+
+ $"\"{EventPropertyKeys.Value}\":{amount}}}}}";
212217
_store.Write(json);
213218

214219
_store.ApplyAnonymousDowngrade();

0 commit comments

Comments
 (0)