Skip to content

Commit 2ff6e44

Browse files
test(audience-sdk): route queue assertions through SDK constants
ImmutableAudienceTests was using inline strings to assert against captured log lines and queue file contents: - Has.Some.Contains("Dropping") for the dropped-event marker that Track / Identify / Alias warns share - "\"purchase\"", "\"identify\"", "\"alias\"" for queue-file content checks (the wire-format envelope's "type" / "eventName" fields) Adds AudienceLogs.DroppingMarker = "Dropping" so the marker has a single source of truth and the test references it directly. Migrates queue-file content checks to interpolate against the SDK's existing EventNames.Purchase, MessageTypes.Identify, and MessageTypes.Alias constants so a backend rename to those wire strings would touch one place rather than scatter across the test. Per the user's "everything random goes in a constant" stance. Follow-up to SDK-272 (centralisation of duplicated literals).
1 parent 456a4ea commit 2ff6e44

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/Packages/Audience/Runtime/Utility/Log.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ internal static string ConsentSyncThrew(Exception ex) =>
8585

8686
internal static class AudienceLogs
8787
{
88+
// Marker shared by Track / Identify / Alias dropped-event log messages.
89+
internal const string DroppingMarker = "Dropping";
90+
91+
8892
// ---- Init / config validation ----
8993

9094
internal const string InitCalledTwice =

src/Packages/Audience/Tests/Runtime/ImmutableAudienceTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,15 +323,15 @@ public void Track_IEventMissingRequiredField_DropsWithWarn()
323323
// Assert the stable parts (event-type name and trailing "Dropping")
324324
// so the test survives any change to the exception type or message.
325325
Assert.That(lines, Has.Some.Contains(nameof(Purchase)));
326-
Assert.That(lines, Has.Some.Contains("Dropping"));
326+
Assert.That(lines, Has.Some.Contains(AudienceLogs.DroppingMarker));
327327
}
328328
finally { Log.Writer = null; }
329329

330330
ImmutableAudience.Shutdown();
331331
var queueDir = AudiencePaths.QueueDir(_testDir);
332332
var contents = Directory.GetFiles(queueDir, AudiencePaths.QueueGlob)
333333
.Select(File.ReadAllText).ToList();
334-
Assert.IsFalse(contents.Any(c => c.Contains("\"purchase\"")),
334+
Assert.IsFalse(contents.Any(c => c.Contains($"\"{EventNames.Purchase}\"")),
335335
"purchase event with missing required Value must be dropped, not enqueued");
336336
}
337337

@@ -608,7 +608,7 @@ public void Track_TypedPurchase_WritesCorrectEventName()
608608
var queueDir = AudiencePaths.QueueDir(_testDir);
609609
var contents = Directory.GetFiles(queueDir, AudiencePaths.QueueGlob)
610610
.Select(File.ReadAllText).ToList();
611-
Assert.IsTrue(contents.Any(c => c.Contains("\"purchase\"")));
611+
Assert.IsTrue(contents.Any(c => c.Contains($"\"{EventNames.Purchase}\"")));
612612
}
613613

614614
// -----------------------------------------------------------------
@@ -627,7 +627,7 @@ public void Identify_FullConsent_WritesIdentifyEvent()
627627
var contents = Directory.GetFiles(queueDir, AudiencePaths.QueueGlob)
628628
.Select(File.ReadAllText).ToList();
629629
Assert.IsTrue(contents.Any(c =>
630-
c.Contains("\"identify\"") && c.Contains("\"76561198012345\"")));
630+
c.Contains($"\"{MessageTypes.Identify}\"") && c.Contains("\"76561198012345\"")));
631631
}
632632

633633
[Test]
@@ -641,7 +641,7 @@ public void Identify_AnonymousConsent_IsIgnored()
641641
var queueDir = AudiencePaths.QueueDir(_testDir);
642642
var contents = Directory.GetFiles(queueDir, AudiencePaths.QueueGlob)
643643
.Select(File.ReadAllText).ToList();
644-
Assert.IsFalse(contents.Any(c => c.Contains("\"identify\"")),
644+
Assert.IsFalse(contents.Any(c => c.Contains($"\"{MessageTypes.Identify}\"")),
645645
"identify should be discarded at Anonymous consent");
646646
}
647647

@@ -657,7 +657,7 @@ public void Alias_FullConsent_WritesAliasEvent()
657657
var contents = Directory.GetFiles(queueDir, AudiencePaths.QueueGlob)
658658
.Select(File.ReadAllText).ToList();
659659
Assert.IsTrue(contents.Any(c =>
660-
c.Contains("\"alias\"") && c.Contains("\"steam123\"")));
660+
c.Contains($"\"{MessageTypes.Alias}\"") && c.Contains("\"steam123\"")));
661661
}
662662

663663
// -----------------------------------------------------------------

0 commit comments

Comments
 (0)