-
Notifications
You must be signed in to change notification settings - Fork 26
test: cover attribution, logging, and ad-tracking pass-through calls #1022
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
eb80aef
test: cover attribution, logging, and ad-tracking pass-through calls
vegaro 96ae4c7
Merge branch 'main' into cesar/unity-wrapper-passthrough-followup
vegaro b7617a5
test: drop tracking pass-through tests duplicated in TrackingTests
vegaro 722e55f
Merge branch 'main' into cesar/unity-wrapper-passthrough-followup
vegaro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
IntegrationTests/Assets/Tests/EditMode/AttributionPassthroughTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| using System; | ||
| using System.Collections; | ||
| using NUnit.Framework; | ||
| using UnityEngine; | ||
|
|
||
| namespace RevenueCat.Tests | ||
| { | ||
| public class AttributionPassthroughTests | ||
| { | ||
| 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() | ||
| { | ||
| // Qualified because `using System` above makes a bare `Object` ambiguous. | ||
| UnityEngine.Object.DestroyImmediate(_gameObject); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Every string attribution setter on <see cref="Purchases"/>. Each case carries the wrapper method it is | ||
| /// expected to reach, the call to make, and the value that must arrive unchanged. | ||
| /// </summary> | ||
| private static IEnumerable StringSetters() | ||
| { | ||
| yield return Setter(nameof(IPurchasesWrapper.SetEmail), | ||
| (purchases, value) => purchases.SetEmail(value), "support@revenuecat.com"); | ||
| yield return Setter(nameof(IPurchasesWrapper.SetPhoneNumber), | ||
| (purchases, value) => purchases.SetPhoneNumber(value), "+15551234567"); | ||
| yield return Setter(nameof(IPurchasesWrapper.SetDisplayName), | ||
| (purchases, value) => purchases.SetDisplayName(value), "Ada Lovelace"); | ||
| yield return Setter(nameof(IPurchasesWrapper.SetPushToken), | ||
| (purchases, value) => purchases.SetPushToken(value), "push_token_1"); | ||
| yield return Setter(nameof(IPurchasesWrapper.SetAdjustID), | ||
| (purchases, value) => purchases.SetAdjustID(value), "adjust_id_1"); | ||
| yield return Setter(nameof(IPurchasesWrapper.SetAppsflyerID), | ||
| (purchases, value) => purchases.SetAppsflyerID(value), "appsflyer_id_1"); | ||
| yield return Setter(nameof(IPurchasesWrapper.SetFBAnonymousID), | ||
| (purchases, value) => purchases.SetFBAnonymousID(value), "fb_anonymous_id_1"); | ||
| yield return Setter(nameof(IPurchasesWrapper.SetMparticleID), | ||
| (purchases, value) => purchases.SetMparticleID(value), "mparticle_id_1"); | ||
| yield return Setter(nameof(IPurchasesWrapper.SetOnesignalID), | ||
| (purchases, value) => purchases.SetOnesignalID(value), "onesignal_id_1"); | ||
| yield return Setter(nameof(IPurchasesWrapper.SetOnesignalUserID), | ||
| (purchases, value) => purchases.SetOnesignalUserID(value), "onesignal_user_id_1"); | ||
| yield return Setter(nameof(IPurchasesWrapper.SetAirshipChannelID), | ||
| (purchases, value) => purchases.SetAirshipChannelID(value), "airship_channel_1"); | ||
| yield return Setter(nameof(IPurchasesWrapper.SetCleverTapID), | ||
| (purchases, value) => purchases.SetCleverTapID(value), "clever_tap_id_1"); | ||
| yield return Setter(nameof(IPurchasesWrapper.SetMixpanelDistinctID), | ||
| (purchases, value) => purchases.SetMixpanelDistinctID(value), "mixpanel_distinct_id_1"); | ||
| yield return Setter(nameof(IPurchasesWrapper.SetFirebaseAppInstanceID), | ||
| (purchases, value) => purchases.SetFirebaseAppInstanceID(value), "firebase_app_instance_id_1"); | ||
| yield return Setter(nameof(IPurchasesWrapper.SetMediaSource), | ||
| (purchases, value) => purchases.SetMediaSource(value), "media_source_1"); | ||
| yield return Setter(nameof(IPurchasesWrapper.SetCampaign), | ||
| (purchases, value) => purchases.SetCampaign(value), "campaign_1"); | ||
| yield return Setter(nameof(IPurchasesWrapper.SetAdGroup), | ||
| (purchases, value) => purchases.SetAdGroup(value), "ad_group_1"); | ||
| yield return Setter(nameof(IPurchasesWrapper.SetAd), | ||
| (purchases, value) => purchases.SetAd(value), "ad_1"); | ||
| yield return Setter(nameof(IPurchasesWrapper.SetKeyword), | ||
| (purchases, value) => purchases.SetKeyword(value), "keyword_1"); | ||
| yield return Setter(nameof(IPurchasesWrapper.SetCreative), | ||
| (purchases, value) => purchases.SetCreative(value), "creative_1"); | ||
| } | ||
|
|
||
| private static TestCaseData Setter(string method, Action<Purchases, string> invoke, string value) | ||
| { | ||
| return new TestCaseData(method, invoke, value) | ||
| .SetName($"{nameof(ForwardsValueToWrapper)}({method})"); | ||
| } | ||
|
|
||
| [TestCaseSource(nameof(StringSetters))] | ||
| public void ForwardsValueToWrapper(string method, Action<Purchases, string> invoke, string value) | ||
| { | ||
| invoke(_purchases, value); | ||
|
|
||
| var invocation = AssertOnlyInvocation(method, 1); | ||
| Assert.That(invocation.Arguments[0], Is.EqualTo(value)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// A null value means "delete this subscriber attribute", so the facade must not filter it out before it | ||
| /// reaches the wrapper. All of the setters above share the same single-statement body, so one representative | ||
| /// case is enough to catch a null guard being introduced. | ||
| /// </summary> | ||
| [Test] | ||
| public void ForwardsNullToWrapper() | ||
| { | ||
| _purchases.SetEmail(null); | ||
|
|
||
| var invocation = AssertOnlyInvocation(nameof(IPurchasesWrapper.SetEmail), 1); | ||
| Assert.That(invocation.Arguments[0], Is.Null); | ||
| } | ||
|
|
||
| private PurchasesWrapperSpy.Invocation AssertOnlyInvocation(string method, int argumentCount) | ||
| { | ||
| Assert.That(_wrapper.Invocations, Has.Count.EqualTo(1)); | ||
|
|
||
| var invocation = _wrapper.Invocations[0]; | ||
| Assert.That(invocation.Method, Is.EqualTo(method)); | ||
| Assert.That(invocation.Arguments, Has.Length.EqualTo(argumentCount)); | ||
| return invocation; | ||
| } | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
IntegrationTests/Assets/Tests/EditMode/AttributionPassthroughTests.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.