Skip to content

Commit 930d017

Browse files
test(audience-sdk): extend TestFixtures with currency, casing, and scenario values
Adds: - Currency code fixtures: UsdCurrency ("USD"), EurCurrency ("EUR"), used across Purchase / Resource typed-event tests - Progression world fixture: ProgressionWorldTutorial ("tutorial"), three uses across TypedEventTests and ImmutableAudienceTests - Exception fixture: ContextProviderBoomMessage ("boom"), for the ContextProvider sabotage test - Disk-block sentinel: DiskBlockerContent ("blocker"), written to the queue directory path so creation fails - DistributionPlatform mixed-case fixtures: DistributionPlatformSteamCased ("Steam"), DistributionPlatformSteamUppercase ("STEAM"), for Init's lowercase-normalisation test - Application.platform fixture: PlatformWindows ("WindowsPlayer"), for the GameLaunch.Platform test - Generic alias endpoint fixtures: GenericAliasFromId ("fromId"), GenericAliasToId ("toId"), GenericAliasFromShort ("from"), for Alias argument-validation tests where the value is filler Migrates inline references in: - Events/TypedEventTests (seven Purchase / Resource currency and Progression world fills) - ImmutableAudienceTests (boom, USD x2, fromId/toId, from, tutorial, Steam, STEAM, WindowsPlayer) - OfflineResilienceTests (blocker) IdentityTypeTests "Steam" / "STEAM" left inline; the wire-format casing fixtures stay self-contained inside that test until the IdentityType wire-format extraction lands. MessagesTests "USD" / "usd" left inline; the literals there appear inside expected error strings being verified, so centralising would defeat the test's own pinning. Per the user's "everything random goes in a constant" stance. Follow-up to SDK-272 (centralisation of duplicated literals).
1 parent f9835e1 commit 930d017

4 files changed

Lines changed: 43 additions & 17 deletions

File tree

src/Packages/Audience/Tests/Runtime/Events/TypedEventTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public void Progression_EventName_IsProgression()
1515
[Test]
1616
public void Progression_WithoutStatus_ThrowsOnToProperties()
1717
{
18-
var evt = new Progression { World = "tutorial" };
18+
var evt = new Progression { World = TestFixtures.ProgressionWorldTutorial };
1919

2020
var ex = Assert.Throws<ArgumentException>(() => evt.ToProperties());
2121
Assert.That(ex!.Message, Does.Contain("Status"));
@@ -27,7 +27,7 @@ public void Progression_Complete_ProducesCorrectProperties()
2727
var evt = new Progression
2828
{
2929
Status = ProgressionStatus.Complete,
30-
World = "tutorial",
30+
World = TestFixtures.ProgressionWorldTutorial,
3131
Level = "1",
3232
Score = 1500,
3333
DurationSec = 120.5f
@@ -36,7 +36,7 @@ public void Progression_Complete_ProducesCorrectProperties()
3636
var props = evt.ToProperties();
3737

3838
Assert.AreEqual(ProgressionStatus.Complete.ToLowercaseString(), props[EventPropertyKeys.Status]);
39-
Assert.AreEqual("tutorial", props[EventPropertyKeys.World]);
39+
Assert.AreEqual(TestFixtures.ProgressionWorldTutorial, props[EventPropertyKeys.World]);
4040
Assert.AreEqual("1", props[EventPropertyKeys.Level]);
4141
Assert.AreEqual(1500, props[EventPropertyKeys.Score]);
4242
Assert.AreEqual(120.5f, props[EventPropertyKeys.DurationSec]);
@@ -114,7 +114,7 @@ public void Purchase_ProducesCorrectProperties()
114114
{
115115
var evt = new Purchase
116116
{
117-
Currency = "USD",
117+
Currency = TestFixtures.UsdCurrency,
118118
Value = 9.99m,
119119
ItemId = TestFixtures.PurchaseItemId,
120120
ItemName = TestFixtures.PurchaseItemName,
@@ -124,7 +124,7 @@ public void Purchase_ProducesCorrectProperties()
124124

125125
var props = evt.ToProperties();
126126

127-
Assert.AreEqual("USD", props[EventPropertyKeys.Currency]);
127+
Assert.AreEqual(TestFixtures.UsdCurrency, props[EventPropertyKeys.Currency]);
128128
Assert.AreEqual(9.99m, props[EventPropertyKeys.Value]);
129129
Assert.AreEqual(TestFixtures.PurchaseItemId, props[EventPropertyKeys.ItemId]);
130130
Assert.AreEqual(TestFixtures.PurchaseItemName, props[EventPropertyKeys.ItemName]);
@@ -135,7 +135,7 @@ public void Purchase_ProducesCorrectProperties()
135135
[Test]
136136
public void Purchase_OptionalFieldsOmitted_WhenNull()
137137
{
138-
var props = new Purchase { Currency = "EUR", Value = 5.00m }.ToProperties();
138+
var props = new Purchase { Currency = TestFixtures.EurCurrency, Value = 5.00m }.ToProperties();
139139

140140
Assert.IsTrue(props.ContainsKey(EventPropertyKeys.Currency));
141141
Assert.IsTrue(props.ContainsKey(EventPropertyKeys.Value));
@@ -163,7 +163,7 @@ public void Purchase_WithoutCurrency_ThrowsOnToProperties()
163163
[Test]
164164
public void Purchase_WithoutValue_ThrowsOnToProperties()
165165
{
166-
var evt = new Purchase { Currency = "USD" };
166+
var evt = new Purchase { Currency = TestFixtures.UsdCurrency };
167167

168168
var ex = Assert.Throws<ArgumentException>(() => evt.ToProperties());
169169
Assert.That(ex!.Message, Does.Contain("Value"));

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public void ContextProvider_Set_MergesOnIdentifyPath()
231231
[Test]
232232
public void ContextProvider_ThrowingDelegate_SwallowsAndShipsBaseContext()
233233
{
234-
ImmutableAudience.ContextProvider = () => throw new InvalidOperationException("boom");
234+
ImmutableAudience.ContextProvider = () => throw new InvalidOperationException(TestFixtures.ContextProviderBoomMessage);
235235

236236
ImmutableAudience.Init(MakeConfig());
237237
ImmutableAudience.Track(TestEventNames.UnitTestEvent);
@@ -319,7 +319,7 @@ public void Track_IEventMissingRequiredField_DropsWithWarn()
319319
{
320320
// Purchase with no Value set: ToProperties throws; Track must
321321
// catch, warn, and drop rather than ship an incomplete event.
322-
Assert.DoesNotThrow(() => ImmutableAudience.Track(new Purchase { Currency = "USD" }));
322+
Assert.DoesNotThrow(() => ImmutableAudience.Track(new Purchase { Currency = TestFixtures.UsdCurrency }));
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)));
@@ -408,7 +408,7 @@ public void Alias_InvalidIdentityTypeCast_Throws()
408408
var invalid = (IdentityType)999;
409409

410410
Assert.Throws<ArgumentOutOfRangeException>(
411-
() => ImmutableAudience.Alias("fromId", invalid, "toId", IdentityType.Steam),
411+
() => ImmutableAudience.Alias(TestFixtures.GenericAliasFromId, invalid, TestFixtures.GenericAliasToId, IdentityType.Steam),
412412
"invalid enum cast must throw so a broken alias call fails loud rather " +
413413
"than shipping an event that cannot be matched for deletion");
414414
}
@@ -419,7 +419,7 @@ public void Alias_NullIds_DoesNotEnqueue()
419419
ImmutableAudience.Init(MakeConfig(ConsentLevel.Full));
420420

421421
Assert.DoesNotThrow(() => ImmutableAudience.Alias(null, IdentityType.Passport, "to", IdentityType.Steam));
422-
Assert.DoesNotThrow(() => ImmutableAudience.Alias("from", IdentityType.Passport, "", IdentityType.Steam));
422+
Assert.DoesNotThrow(() => ImmutableAudience.Alias(TestFixtures.GenericAliasFromShort, IdentityType.Passport, "", IdentityType.Steam));
423423
}
424424

425425
[Test]
@@ -581,7 +581,7 @@ public void Track_TypedProgression_WritesCorrectEventName()
581581
ImmutableAudience.Track(new Progression
582582
{
583583
Status = ProgressionStatus.Complete,
584-
World = "tutorial",
584+
World = TestFixtures.ProgressionWorldTutorial,
585585
Level = "1"
586586
});
587587
ImmutableAudience.Shutdown();
@@ -600,7 +600,7 @@ public void Track_TypedPurchase_WritesCorrectEventName()
600600

601601
ImmutableAudience.Track(new Purchase
602602
{
603-
Currency = "USD",
603+
Currency = TestFixtures.UsdCurrency,
604604
Value = 9.99m
605605
});
606606
ImmutableAudience.Shutdown();
@@ -1124,7 +1124,7 @@ public void Init_GameLaunch_IncludesDistributionPlatform()
11241124
public void Init_LowercasesDistributionPlatform_WhenCallerPassesMixedCase()
11251125
{
11261126
var config = MakeConfig();
1127-
config.DistributionPlatform = "Steam";
1127+
config.DistributionPlatform = TestFixtures.DistributionPlatformSteamCased;
11281128
ImmutableAudience.Init(config);
11291129

11301130
Assert.AreEqual(DistributionPlatforms.Steam, config.DistributionPlatform,
@@ -1135,7 +1135,7 @@ public void Init_LowercasesDistributionPlatform_WhenCallerPassesMixedCase()
11351135
public void Init_LowercasesDistributionPlatform_WhenCallerPassesAllUpperCase()
11361136
{
11371137
var config = MakeConfig();
1138-
config.DistributionPlatform = "STEAM";
1138+
config.DistributionPlatform = TestFixtures.DistributionPlatformSteamUppercase;
11391139
ImmutableAudience.Init(config);
11401140

11411141
Assert.AreEqual(DistributionPlatforms.Steam, config.DistributionPlatform);
@@ -1199,7 +1199,7 @@ public void Init_GameLaunch_IncludesLaunchContextProviderFields()
11991199
{
12001200
ImmutableAudience.LaunchContextProvider = () => new Dictionary<string, object>
12011201
{
1202-
[GameLaunchPropertyKeys.Platform] = "WindowsPlayer",
1202+
[GameLaunchPropertyKeys.Platform] = TestFixtures.PlatformWindows,
12031203
[GameLaunchPropertyKeys.Version] = "1.2.3",
12041204
[GameLaunchPropertyKeys.BuildGuid] = "a1b2c3d4e5f6",
12051205
[GameLaunchPropertyKeys.UnityVersion] = "2022.3.20f1",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private void BlockDiskWrites()
6464
foreach (var f in Directory.GetFiles(queueDir, AudiencePaths.QueueGlob)) File.Delete(f);
6565
Directory.Delete(queueDir);
6666
}
67-
File.WriteAllText(queueDir, "blocker");
67+
File.WriteAllText(queueDir, TestFixtures.DiskBlockerContent);
6868
}
6969

7070
// -----------------------------------------------------------------

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,31 @@ internal static class TestFixtures
6666
internal const string GenericToId = "t";
6767
internal const string GenericFromType = "t1";
6868
internal const string GenericToType = "t2";
69+
70+
// ISO 4217 currency codes used by Purchase / Resource tests.
71+
internal const string UsdCurrency = "USD";
72+
internal const string EurCurrency = "EUR";
73+
74+
// Progression.World fixture (used in three typed-event tests).
75+
internal const string ProgressionWorldTutorial = "tutorial";
76+
77+
// Exception message fixture for the ContextProvider sabotage test.
78+
internal const string ContextProviderBoomMessage = "boom";
79+
80+
// File body that occupies the queue directory path so directory creation fails.
81+
internal const string DiskBlockerContent = "blocker";
82+
83+
// DistributionPlatform mixed-case fixtures for Init's lowercase
84+
// normalisation test.
85+
internal const string DistributionPlatformSteamCased = "Steam";
86+
internal const string DistributionPlatformSteamUppercase = "STEAM";
87+
88+
// Unity Application.platform string for the GameLaunch.Platform test.
89+
internal const string PlatformWindows = "WindowsPlayer";
90+
91+
// Longer generic alias endpoint fixtures, for readability in Alias calls.
92+
internal const string GenericAliasFromId = "fromId";
93+
internal const string GenericAliasToId = "toId";
94+
internal const string GenericAliasFromShort = "from";
6995
}
7096
}

0 commit comments

Comments
 (0)