-
Notifications
You must be signed in to change notification settings - Fork 26
Add configuration and harness smoke tests #1014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
3af09b8
d45f6a0
115d745
14a1b01
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| using NUnit.Framework; | ||
| using RevenueCat.SimpleJSON; | ||
|
|
||
| namespace RevenueCat.Tests | ||
| { | ||
| public class JsonModelTests | ||
| { | ||
| [Test] | ||
| public void VirtualCurrenciesParsesCurrenciesByCode() | ||
| { | ||
| var response = JSONNode.Parse( | ||
| "{\"all\":{" + | ||
| "\"COIN\":{\"balance\":120,\"name\":\"Coins\",\"code\":\"COIN\",\"serverDescription\":\"Earned in game\"}," + | ||
| "\"GEM\":{\"balance\":4,\"name\":\"Gems\",\"code\":\"GEM\",\"serverDescription\":null}" + | ||
| "}}" | ||
| ); | ||
|
|
||
| var virtualCurrencies = new Purchases.VirtualCurrencies(response); | ||
|
|
||
| Assert.That(virtualCurrencies.All.Keys, Is.EquivalentTo(new[] { "COIN", "GEM" })); | ||
| Assert.That(virtualCurrencies.All["COIN"].Balance, Is.EqualTo(120)); | ||
| Assert.That(virtualCurrencies.All["COIN"].Name, Is.EqualTo("Coins")); | ||
| Assert.That(virtualCurrencies.All["COIN"].ServerDescription, Is.EqualTo("Earned in game")); | ||
| Assert.That(virtualCurrencies.All["GEM"].Balance, Is.EqualTo(4)); | ||
| Assert.That(virtualCurrencies.All["GEM"].ServerDescription, Is.Null); | ||
| } | ||
|
|
||
| [Test] | ||
| public void SubscriptionPriceSupportsValuesAboveInt32Range() | ||
| { | ||
| var response = JSONNode.Parse( | ||
| "{\"formatted\":\"$4,294.97\",\"amountMicros\":4294970000,\"currencyCode\":\"USD\"}" | ||
| ); | ||
|
|
||
| var price = new Purchases.SubscriptionOption.Price(response); | ||
|
|
||
| Assert.That(price.AmountMicros, Is.EqualTo(4294970000L)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void StoreProductFallsBackToUnknownProductCategory() | ||
| { | ||
| var response = JSONNode.Parse( | ||
| "{\"title\":\"Lifetime\",\"identifier\":\"lifetime\",\"description\":\"Lifetime access\"," + | ||
| "\"price\":99.99,\"priceString\":\"$99.99\",\"currencyCode\":\"USD\"," + | ||
| "\"productCategory\":\"UNRECOGNIZED\"}" | ||
| ); | ||
|
|
||
| var product = new Purchases.StoreProduct(response); | ||
|
|
||
| Assert.That(product.Identifier, Is.EqualTo("lifetime")); | ||
| Assert.That(product.ProductCategory, Is.EqualTo(Purchases.ProductCategory.UNKNOWN)); | ||
|
vegaro marked this conversation as resolved.
|
||
| Assert.That(product.DefaultOption, Is.Null); | ||
| Assert.That(product.Discounts, Is.Null); | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| using NUnit.Framework; | ||
| using RevenueCat.SimpleJSON; | ||
|
|
||
| namespace RevenueCat.Tests | ||
| { | ||
| public class PresentedOfferingContextTests | ||
| { | ||
| [Test] | ||
| public void JsonRoundTripPreservesAllContext() | ||
| { | ||
| var originalJson = JSONNode.Parse( | ||
| "{\"offeringIdentifier\":\"default\",\"placementIdentifier\":\"onboarding\"," + | ||
| "\"targetingContext\":{\"revision\":7,\"ruleId\":\"rule-id\"}}" | ||
| ); | ||
|
|
||
| var context = new Purchases.PresentedOfferingContext(originalJson); | ||
| var serializedContext = JSONNode.Parse(context.ToJsonString()); | ||
|
|
||
| Assert.That(serializedContext["offeringIdentifier"].Value, Is.EqualTo("default")); | ||
| Assert.That(serializedContext["placementIdentifier"].Value, Is.EqualTo("onboarding")); | ||
| Assert.That(serializedContext["targetingContext"]["revision"].AsInt, Is.EqualTo(7)); | ||
| Assert.That(serializedContext["targetingContext"]["ruleId"].Value, Is.EqualTo("rule-id")); | ||
| } | ||
|
|
||
| [Test] | ||
| public void OfferingIdentifierConstructorOmitsOptionalContext() | ||
| { | ||
| var context = new Purchases.PresentedOfferingContext("default"); | ||
| var serializedContext = JSONNode.Parse(context.ToJsonString()); | ||
|
|
||
| Assert.That(serializedContext["offeringIdentifier"].Value, Is.EqualTo("default")); | ||
| Assert.That(serializedContext.HasKey("placementIdentifier"), Is.False); | ||
| Assert.That(serializedContext.HasKey("targetingContext"), Is.False); | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| using NUnit.Framework; | ||
| using RevenueCat.SimpleJSON; | ||
| using UnityEngine; | ||
|
|
||
| namespace RevenueCat.Tests | ||
| { | ||
| public class PurchasesCallTests | ||
| { | ||
| private GameObject _gameObject; | ||
| private Purchases _purchases; | ||
| private PurchasesWrapperSpy _wrapper; | ||
|
|
||
| [SetUp] | ||
| public void SetUp() | ||
| { | ||
| _gameObject = new GameObject("RevenueCatTests"); | ||
| _purchases = _gameObject.AddComponent<Purchases>(); | ||
| _wrapper = new PurchasesWrapperSpy(); | ||
| _purchases.SetWrapper(_wrapper); | ||
| } | ||
|
|
||
| [TearDown] | ||
| public void TearDown() | ||
| { | ||
| Object.DestroyImmediate(_gameObject); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ConfigureForwardsEveryConfigurationValue() | ||
| { | ||
| var configuration = Purchases.PurchasesConfiguration.Builder | ||
| .Init("test_api_key") | ||
| .SetAppUserId("app_user_id") | ||
| .SetPurchasesAreCompletedBy(Purchases.PurchasesAreCompletedBy.MyApp, | ||
| Purchases.StoreKitVersion.StoreKit2) | ||
| .SetUserDefaultsSuiteName("suite_name") | ||
| .SetUseAmazon(true) | ||
| .SetDangerousSettings(new Purchases.DangerousSettings(false)) | ||
| .SetShouldShowInAppMessagesAutomatically(true) | ||
| .SetEntitlementVerificationMode(Purchases.EntitlementVerificationMode.Informational) | ||
| .SetPendingTransactionsForPrepaidPlansEnabled(true) | ||
| .SetDiagnosticsEnabled(true) | ||
| .SetAutomaticDeviceIdentifierCollectionEnabled(false) | ||
| .SetPreferredUILocaleOverride("de_DE") | ||
| .Build(); | ||
|
|
||
| _purchases.Configure(configuration); | ||
|
|
||
| var invocation = AssertLastInvocation(nameof(IPurchasesWrapper.Setup), 14); | ||
| Assert.That(invocation.Arguments[0], Is.EqualTo(_gameObject.name)); | ||
| Assert.That(invocation.Arguments[1], Is.EqualTo("test_api_key")); | ||
| Assert.That(invocation.Arguments[2], Is.EqualTo("app_user_id")); | ||
| Assert.That(invocation.Arguments[3], Is.EqualTo(Purchases.PurchasesAreCompletedBy.MyApp)); | ||
| Assert.That(invocation.Arguments[4], Is.EqualTo(Purchases.StoreKitVersion.StoreKit2)); | ||
| Assert.That(invocation.Arguments[5], Is.EqualTo("suite_name")); | ||
| Assert.That(invocation.Arguments[6], Is.True); | ||
|
vegaro marked this conversation as resolved.
|
||
| Assert.That(JSONNode.Parse((string)invocation.Arguments[7])["AutoSyncPurchases"].AsBool, Is.False); | ||
| Assert.That(invocation.Arguments[8], Is.True); | ||
| Assert.That(invocation.Arguments[9], Is.EqualTo(Purchases.EntitlementVerificationMode.Informational)); | ||
| Assert.That(invocation.Arguments[10], Is.True); | ||
| Assert.That(invocation.Arguments[11], Is.True); | ||
| Assert.That(invocation.Arguments[12], Is.False); | ||
| Assert.That(invocation.Arguments[13], Is.EqualTo("de_DE")); | ||
| } | ||
|
|
||
| private PurchasesWrapperSpy.Invocation AssertLastInvocation(string method, int argumentCount) | ||
|
vegaro marked this conversation as resolved.
Outdated
|
||
| { | ||
| Assert.That(_wrapper.Invocations, Has.Count.EqualTo(1)); | ||
| Assert.That(_wrapper.LastInvocation.Method, Is.EqualTo(method)); | ||
| Assert.That(_wrapper.LastInvocation.Arguments, Has.Length.EqualTo(argumentCount)); | ||
| return _wrapper.LastInvocation; | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| using NUnit.Framework; | ||
|
|
||
| namespace RevenueCat.Tests | ||
| { | ||
| public class PurchasesConfigurationTests | ||
| { | ||
| [Test] | ||
| public void BuildUsesDocumentedDefaults() | ||
| { | ||
| var configuration = Purchases.PurchasesConfiguration.Builder | ||
| .Init("test_api_key") | ||
| .Build(); | ||
|
|
||
| Assert.That(configuration.ApiKey, Is.EqualTo("test_api_key")); | ||
| Assert.That(configuration.AppUserId, Is.Null); | ||
| Assert.That(configuration.PurchasesAreCompletedBy, Is.EqualTo(default(Purchases.PurchasesAreCompletedBy))); | ||
| Assert.That(configuration.UserDefaultsSuiteName, Is.Null); | ||
| Assert.That(configuration.UseAmazon, Is.False); | ||
| Assert.That(configuration.DangerousSettings.AutoSyncPurchases, Is.True); | ||
| Assert.That(configuration.StoreKitVersion, Is.EqualTo(default(Purchases.StoreKitVersion))); | ||
|
vegaro marked this conversation as resolved.
Outdated
|
||
| Assert.That(configuration.ShouldShowInAppMessagesAutomatically, Is.False); | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| Assert.That(configuration.EntitlementVerificationMode, Is.EqualTo(default(Purchases.EntitlementVerificationMode))); | ||
|
vegaro marked this conversation as resolved.
Outdated
|
||
| Assert.That(configuration.PendingTransactionsForPrepaidPlansEnabled, Is.False); | ||
| Assert.That(configuration.DiagnosticsEnabled, Is.False); | ||
| Assert.That(configuration.AutomaticDeviceIdentifierCollectionEnabled, Is.True); | ||
| Assert.That(configuration.PreferredUILocaleOverride, Is.Null); | ||
| } | ||
|
|
||
| [Test] | ||
| public void BuildUsesConfiguredValues() | ||
| { | ||
| var dangerousSettings = new Purchases.DangerousSettings(false); | ||
|
|
||
| var configuration = Purchases.PurchasesConfiguration.Builder | ||
| .Init("test_api_key") | ||
| .SetAppUserId("app_user_id") | ||
| .SetPurchasesAreCompletedBy(Purchases.PurchasesAreCompletedBy.MyApp, Purchases.StoreKitVersion.StoreKit2) | ||
| .SetUserDefaultsSuiteName("suite_name") | ||
| .SetUseAmazon(true) | ||
| .SetDangerousSettings(dangerousSettings) | ||
| .SetShouldShowInAppMessagesAutomatically(true) | ||
| .SetEntitlementVerificationMode(Purchases.EntitlementVerificationMode.Informational) | ||
| .SetPendingTransactionsForPrepaidPlansEnabled(true) | ||
| .SetDiagnosticsEnabled(true) | ||
| .SetAutomaticDeviceIdentifierCollectionEnabled(false) | ||
| .SetPreferredUILocaleOverride("de_DE") | ||
| .Build(); | ||
|
|
||
| Assert.That(configuration.AppUserId, Is.EqualTo("app_user_id")); | ||
| Assert.That(configuration.PurchasesAreCompletedBy, Is.EqualTo(Purchases.PurchasesAreCompletedBy.MyApp)); | ||
| Assert.That(configuration.StoreKitVersion, Is.EqualTo(Purchases.StoreKitVersion.StoreKit2)); | ||
| Assert.That(configuration.UserDefaultsSuiteName, Is.EqualTo("suite_name")); | ||
| Assert.That(configuration.UseAmazon, Is.True); | ||
| Assert.That(configuration.DangerousSettings, Is.SameAs(dangerousSettings)); | ||
| Assert.That(configuration.ShouldShowInAppMessagesAutomatically, Is.True); | ||
| Assert.That(configuration.EntitlementVerificationMode, Is.EqualTo(Purchases.EntitlementVerificationMode.Informational)); | ||
| Assert.That(configuration.PendingTransactionsForPrepaidPlansEnabled, Is.True); | ||
| Assert.That(configuration.DiagnosticsEnabled, Is.True); | ||
| Assert.That(configuration.AutomaticDeviceIdentifierCollectionEnabled, Is.False); | ||
| Assert.That(configuration.PreferredUILocaleOverride, Is.EqualTo("de_DE")); | ||
| } | ||
|
|
||
| [Test] | ||
| public void BuildRestoresDefaultDangerousSettingsWhenSetToNull() | ||
| { | ||
| var configuration = Purchases.PurchasesConfiguration.Builder | ||
| .Init("test_api_key") | ||
| .SetDangerousSettings(null) | ||
| .Build(); | ||
|
|
||
| Assert.That(configuration.DangerousSettings, Is.Not.Null); | ||
| Assert.That(configuration.DangerousSettings.AutoSyncPurchases, Is.True); | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Null currency description assertion fails
High Severity
VirtualCurrenciesParsesCurrenciesByCodeexpectsServerDescriptionto be C# null for a JSONnull, but SimpleJSON's string conversion returns the literal"null"fromJSONNull.Value. The assertion fails against current parsing behavior.Reviewed by Cursor Bugbot for commit 3af09b8. Configure here.