Added docs and test

This commit is contained in:
Savya Bikram Shah
2026-05-07 17:33:26 +05:45
parent 3c17829453
commit 9f620084b2
112 changed files with 589 additions and 574 deletions

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 98341f79b8169426c8edbc4469715037
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,29 +0,0 @@
using UnityEngine;
using UnityEditor;
using UnityEngine.TestTools;
using NUnit.Framework;
using System.Collections;
namespace Voidbotz.Fonepayunity.Editor.Tests
{
class EditorExampleTest
{
[Test]
public void EditorSampleTestSimplePasses()
{
// Use the Assert class to test conditions.
}
// A UnityTest behaves like a coroutine in PlayMode
// and allows you to yield null to skip a frame in EditMode
[UnityTest]
public IEnumerator EditorSampleTestWithEnumeratorPasses()
{
// Use the Assert class to test conditions.
// yield to skip a frame
yield return null;
}
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 382d5d15b2d9e4789aac53c1b86194b0

View File

@@ -1,14 +0,0 @@
{
"name": "Voidbotz.Fonepayunity.Editor.Tests",
"references": [
"Voidbotz.Fonepayunity.Editor",
"Voidbotz.Fonepayunity"
],
"optionalUnityReferences": [
"TestAssemblies"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": []
}

View File

@@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 2a4ef70a61be54ea6b8ada95c5e2743c
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 6639ec7313a77493fb517eb322745684
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,91 @@
using System;
using System.Collections;
using System.Threading;
using System.Threading.Tasks;
using Darkmatter.Fonepay;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
namespace Darkmatter.FonepayUnity.Tests
{
public class WebsocketMessagePlayModeTests
{
[Test]
public void Status_ParsesNestedJsonInPlayer()
{
const string raw =
"{\"transactionStatus\":\"{\\\"paymentSuccess\\\":true,\\\"success\\\":true,\\\"amount\\\":7}\"}";
var envelope = JsonUtility.FromJson<WebsocketMessage<QRPaymentStatus>>(raw);
var status = envelope.Status;
Assert.IsTrue(status.paymentSuccess);
Assert.AreEqual(7f, status.amount);
Assert.AreEqual(PaymentOutcome.Complete, status.Outcome);
}
[Test]
public void Status_ReparsesEachAccess()
{
const string raw =
"{\"transactionStatus\":\"{\\\"success\\\":true,\\\"paymentSuccess\\\":true}\"}";
var envelope = JsonUtility.FromJson<WebsocketMessage<QRPaymentStatus>>(raw);
var a = envelope.Status;
var b = envelope.Status;
Assert.AreEqual(a.Outcome, b.Outcome);
Assert.AreEqual(PaymentOutcome.Complete, a.Outcome);
}
}
public class FonepayClientPlayModeTests
{
[SetUp]
public void Reset() => FonepayConfig.Invalidate();
[Test]
public void Ctor_WithoutConfigAsset_Throws()
{
// No FonepayConfig resource in test context → Load() throws FonepayError.
Assert.Throws<FonepayError>(() => new FonepayClient());
}
[UnityTest]
public IEnumerator AwaitPaymentAsync_EmptyUrl_Throws() => RunAsync(async () =>
{
var client = TryBuildClient();
if (client == null) Assert.Pass("Skipped: no FonepayConfig in test context.");
Assert.ThrowsAsync<ArgumentException>(async () =>
await client.AwaitPaymentAsync(string.Empty));
});
[UnityTest]
public IEnumerator AwaitPaymentAsync_PreCancelled_Throws() => RunAsync(async () =>
{
var client = TryBuildClient();
if (client == null) Assert.Pass("Skipped: no FonepayConfig in test context.");
using var cts = new CancellationTokenSource();
cts.Cancel();
Assert.ThrowsAsync<OperationCanceledException>(async () =>
await client.AwaitPaymentAsync("ws://127.0.0.1:1/", ct: cts.Token));
});
private static FonepayClient TryBuildClient()
{
try { return new FonepayClient(); }
catch (FonepayError) { return null; }
}
private static IEnumerator RunAsync(Func<Task> body)
{
var t = body();
while (!t.IsCompleted) yield return null;
if (t.IsFaulted) throw t.Exception;
}
}
}

View File

@@ -1,28 +0,0 @@
using UnityEngine;
using UnityEngine.TestTools;
using NUnit.Framework;
using System.Collections;
namespace Voidbotz.Fonepayunity.Tests
{
class RuntimeExampleTest
{
[Test]
public void PlayModeSampleTestSimplePasses()
{
// Use the Assert class to test conditions.
}
// A UnityTest behaves like a coroutine in PlayMode
// and allows you to yield null to skip a frame in EditMode
[UnityTest]
public IEnumerator PlayModeSampleTestWithEnumeratorPasses()
{
// Use the Assert class to test conditions.
// yield to skip a frame
yield return null;
}
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: e9d969af7bf1a46f0a0c37692d7d862f

View File

@@ -1,11 +0,0 @@
{
"name": "Voidbotz.Fonepayunity.Tests",
"references": [
"Voidbotz.Fonepayunity"
],
"optionalUnityReferences": [
"TestAssemblies"
],
"includePlatforms": [],
"excludePlatforms": []
}

View File

@@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 5b7c0851a1002412dadc7d1c37a4cef5
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: