Skip to content

Commit ba8c062

Browse files
test(audience-sdk): cover IdentityTypeExtensions.ParseLowercaseString
ParseLowercaseString was added in the SDK-272 stack as the inverse of ToLowercaseString and consumed by the sample app to map wire strings back to the enum. It had no direct test, so a typo in any of the eight case branches or in the Custom fallback would land silently. Add three parametrised cases: - Each known enum value maps from its lowercase wire form. - Mixed-case ("Steam", "STEAM", "Passport") still resolves via ToLowerInvariant, matching the documented behaviour. - null, empty, and unknown values fall back to Custom (the parser never throws so producer code always gets a usable enum). Follow-up to SDK-272 (centralisation of duplicated literals).
1 parent 710a756 commit ba8c062

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,37 @@ public void ToLowercaseString_MapsEachEnumValueToLowercaseBackendString(Identity
1919
Assert.AreEqual(expected, type.ToLowercaseString());
2020
}
2121

22+
[TestCase("passport", IdentityType.Passport)]
23+
[TestCase("steam", IdentityType.Steam)]
24+
[TestCase("epic", IdentityType.Epic)]
25+
[TestCase("google", IdentityType.Google)]
26+
[TestCase("apple", IdentityType.Apple)]
27+
[TestCase("discord", IdentityType.Discord)]
28+
[TestCase("email", IdentityType.Email)]
29+
[TestCase("custom", IdentityType.Custom)]
30+
public void ParseLowercaseString_MapsKnownStringToEnum(string wire, IdentityType expected)
31+
{
32+
Assert.AreEqual(expected, IdentityTypeExtensions.ParseLowercaseString(wire));
33+
}
34+
35+
[TestCase("Steam", IdentityType.Steam)]
36+
[TestCase("STEAM", IdentityType.Steam)]
37+
[TestCase("Passport", IdentityType.Passport)]
38+
public void ParseLowercaseString_AcceptsMixedCase(string wire, IdentityType expected)
39+
{
40+
Assert.AreEqual(expected, IdentityTypeExtensions.ParseLowercaseString(wire));
41+
}
42+
43+
[TestCase(null)]
44+
[TestCase("")]
45+
[TestCase("unknown_provider")]
46+
[TestCase("steamX")]
47+
public void ParseLowercaseString_FallsBackToCustomForUnknownOrEmpty(string? wire)
48+
{
49+
// ParseLowercaseString never throws; unknown values map to Custom.
50+
Assert.AreEqual(IdentityType.Custom, IdentityTypeExtensions.ParseLowercaseString(wire));
51+
}
52+
2253
[Test]
2354
public void ToLowercaseString_UnknownValue_Throws()
2455
{

0 commit comments

Comments
 (0)