Skip to content

Commit 2f1094a

Browse files
committed
Add integration tests
1 parent 8569c96 commit 2f1094a

File tree

4 files changed

+216
-0
lines changed

4 files changed

+216
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using NUnit.Framework;
2+
using RevenueCatUI;
3+
4+
namespace RevenueCatUI.Tests
5+
{
6+
public class PaywallOptionsAPITests
7+
{
8+
[Test]
9+
public void PaywallOptions_DefaultConstructor_CreatesInstanceWithNullValues()
10+
{
11+
var options = new PaywallOptions();
12+
13+
Assert.IsNotNull(options);
14+
Assert.IsNull(options.OfferingIdentifier);
15+
Assert.IsFalse(options.DisplayCloseButton);
16+
}
17+
18+
[Test]
19+
public void PaywallOptions_OfferingIdentifierConstructor_SetsOfferingIdentifier()
20+
{
21+
const string offeringId = "test_offering";
22+
var options = new PaywallOptions(offeringId);
23+
24+
Assert.IsNotNull(options);
25+
Assert.AreEqual(offeringId, options.OfferingIdentifier);
26+
Assert.IsFalse(options.DisplayCloseButton);
27+
}
28+
29+
[Test]
30+
public void PaywallOptions_FullConstructor_SetsBothProperties()
31+
{
32+
const string offeringId = "test_offering";
33+
const bool displayCloseButton = true;
34+
var options = new PaywallOptions(offeringId, displayCloseButton);
35+
36+
Assert.IsNotNull(options);
37+
Assert.AreEqual(offeringId, options.OfferingIdentifier);
38+
Assert.AreEqual(displayCloseButton, options.DisplayCloseButton);
39+
}
40+
41+
[Test]
42+
public void PaywallOptions_Properties_CanBeSetAndRead()
43+
{
44+
var options = new PaywallOptions
45+
{
46+
OfferingIdentifier = "custom_offering",
47+
DisplayCloseButton = true
48+
};
49+
50+
Assert.AreEqual("custom_offering", options.OfferingIdentifier);
51+
Assert.IsTrue(options.DisplayCloseButton);
52+
}
53+
}
54+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using NUnit.Framework;
2+
using RevenueCatUI;
3+
4+
namespace RevenueCatUI.Tests
5+
{
6+
public class PaywallResultAPITests
7+
{
8+
[Test]
9+
public void PaywallResultType_EnumValues_AreCorrect()
10+
{
11+
// Test that all expected enum values exist
12+
Assert.IsTrue(System.Enum.IsDefined(typeof(PaywallResultType), PaywallResultType.NotPresented));
13+
Assert.IsTrue(System.Enum.IsDefined(typeof(PaywallResultType), PaywallResultType.Cancelled));
14+
Assert.IsTrue(System.Enum.IsDefined(typeof(PaywallResultType), PaywallResultType.Error));
15+
Assert.IsTrue(System.Enum.IsDefined(typeof(PaywallResultType), PaywallResultType.Purchased));
16+
Assert.IsTrue(System.Enum.IsDefined(typeof(PaywallResultType), PaywallResultType.Restored));
17+
}
18+
19+
[Test]
20+
public void PaywallResult_Constructor_SetsResultType()
21+
{
22+
var result = new PaywallResult(PaywallResultType.Purchased);
23+
24+
Assert.IsNotNull(result);
25+
Assert.AreEqual(PaywallResultType.Purchased, result.Result);
26+
}
27+
28+
[Test]
29+
public void PaywallResult_Constructor_WithAllResultTypes_WorksCorrectly()
30+
{
31+
// Test creating PaywallResult with each enum value
32+
var notPresentedResult = new PaywallResult(PaywallResultType.NotPresented);
33+
Assert.AreEqual(PaywallResultType.NotPresented, notPresentedResult.Result);
34+
35+
var cancelledResult = new PaywallResult(PaywallResultType.Cancelled);
36+
Assert.AreEqual(PaywallResultType.Cancelled, cancelledResult.Result);
37+
38+
var errorResult = new PaywallResult(PaywallResultType.Error);
39+
Assert.AreEqual(PaywallResultType.Error, errorResult.Result);
40+
41+
var purchasedResult = new PaywallResult(PaywallResultType.Purchased);
42+
Assert.AreEqual(PaywallResultType.Purchased, purchasedResult.Result);
43+
44+
var restoredResult = new PaywallResult(PaywallResultType.Restored);
45+
Assert.AreEqual(PaywallResultType.Restored, restoredResult.Result);
46+
}
47+
48+
[Test]
49+
public void PaywallResultTypeExtensions_ToNativeString_ReturnsValidStrings()
50+
{
51+
Assert.IsNotNull(PaywallResultTypeExtensions.ToNativeString(PaywallResultType.NotPresented));
52+
Assert.IsNotNull(PaywallResultTypeExtensions.ToNativeString(PaywallResultType.Cancelled));
53+
Assert.IsNotNull(PaywallResultTypeExtensions.ToNativeString(PaywallResultType.Error));
54+
Assert.IsNotNull(PaywallResultTypeExtensions.ToNativeString(PaywallResultType.Purchased));
55+
Assert.IsNotNull(PaywallResultTypeExtensions.ToNativeString(PaywallResultType.Restored));
56+
}
57+
58+
[Test]
59+
public void PaywallResultTypeExtensions_FromNativeString_HandlesValidStrings()
60+
{
61+
// Test roundtrip conversion for each enum value
62+
foreach (PaywallResultType enumValue in System.Enum.GetValues(typeof(PaywallResultType)))
63+
{
64+
var nativeString = PaywallResultTypeExtensions.ToNativeString(enumValue);
65+
var convertedBack = PaywallResultTypeExtensions.FromNativeString(nativeString);
66+
Assert.AreEqual(enumValue, convertedBack);
67+
}
68+
}
69+
}
70+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using NUnit.Framework;
2+
using RevenueCatUI;
3+
using System.Threading.Tasks;
4+
5+
namespace RevenueCatUI.Tests
6+
{
7+
public class PaywallsPresenterAPITests
8+
{
9+
[Test]
10+
public void PaywallsPresenter_Present_MethodExists()
11+
{
12+
// Test that the method exists and can be called
13+
var task = PaywallsPresenter.Present();
14+
15+
Assert.IsNotNull(task);
16+
Assert.IsInstanceOf<Task<PaywallResult>>(task);
17+
}
18+
19+
[Test]
20+
public void PaywallsPresenter_PresentWithOptions_MethodExists()
21+
{
22+
var options = new PaywallOptions("test_offering", true);
23+
var task = PaywallsPresenter.Present(options);
24+
25+
Assert.IsNotNull(task);
26+
Assert.IsInstanceOf<Task<PaywallResult>>(task);
27+
}
28+
29+
[Test]
30+
public void PaywallsPresenter_PresentIfNeeded_MethodExists()
31+
{
32+
const string entitlementId = "test_entitlement";
33+
var task = PaywallsPresenter.PresentIfNeeded(entitlementId);
34+
35+
Assert.IsNotNull(task);
36+
Assert.IsInstanceOf<Task<PaywallResult>>(task);
37+
}
38+
39+
[Test]
40+
public void PaywallsPresenter_PresentIfNeededWithOptions_MethodExists()
41+
{
42+
const string entitlementId = "test_entitlement";
43+
var options = new PaywallOptions("test_offering", false);
44+
var task = PaywallsPresenter.PresentIfNeeded(entitlementId, options);
45+
46+
Assert.IsNotNull(task);
47+
Assert.IsInstanceOf<Task<PaywallResult>>(task);
48+
}
49+
50+
[Test]
51+
public void PaywallsPresenter_PresentWithNullOptions_DoesNotThrow()
52+
{
53+
Assert.DoesNotThrow(() =>
54+
{
55+
var task = PaywallsPresenter.Present(null);
56+
Assert.IsNotNull(task);
57+
});
58+
}
59+
60+
[Test]
61+
public void PaywallsPresenter_PresentIfNeededWithNullOptions_DoesNotThrow()
62+
{
63+
Assert.DoesNotThrow(() =>
64+
{
65+
var task = PaywallsPresenter.PresentIfNeeded("test_entitlement", null);
66+
Assert.IsNotNull(task);
67+
});
68+
}
69+
}
70+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "revenuecat.purchases-unity-ui.Tests",
3+
"rootNamespace": "RevenueCatUI.Tests",
4+
"references": [
5+
"revenuecat.purchases-unity-ui",
6+
"revenuecat.purchases-unity",
7+
"UnityEngine.TestRunner"
8+
],
9+
"includePlatforms": [],
10+
"excludePlatforms": [],
11+
"allowUnsafeCode": false,
12+
"overrideReferences": true,
13+
"precompiledReferences": [
14+
"nunit.framework.dll"
15+
],
16+
"autoReferenced": false,
17+
"defineConstraints": [
18+
"UNITY_INCLUDE_TESTS"
19+
],
20+
"versionDefines": [],
21+
"noEngineReferences": false
22+
}

0 commit comments

Comments
 (0)