Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b126a15
pigeon stuff
LouiseHsu Sep 3, 2024
ae9095a
refactored AND working heh
LouiseHsu Sep 4, 2024
c38b66f
format
LouiseHsu Sep 4, 2024
268a50e
pre refactor for cache
LouiseHsu Sep 4, 2024
f6ec07a
.
LouiseHsu Sep 4, 2024
aa36dfd
fix configuration file
LouiseHsu Sep 5, 2024
8724d40
more docs
LouiseHsu Sep 5, 2024
a6cbd98
more docs and clean up
LouiseHsu Sep 5, 2024
b75eec7
.
LouiseHsu Sep 13, 2024
4d2fd59
FIXED TESTING ISSUE
LouiseHsu Sep 24, 2024
aeef979
native tests are donesies
LouiseHsu Sep 25, 2024
acf499f
moreeee clean up and tests,
LouiseHsu Sep 26, 2024
c3c7204
format, comments, remove prints
LouiseHsu Sep 26, 2024
9021b6f
versioning, analyze
LouiseHsu Sep 26, 2024
666df56
symlink the test files
LouiseHsu Sep 26, 2024
97b746f
fix mac cant build
LouiseHsu Sep 26, 2024
add5bf5
podspec, licensing
LouiseHsu Sep 26, 2024
06b42d0
.
LouiseHsu Sep 27, 2024
0701d2a
remove any to get around old linter
LouiseHsu Sep 27, 2024
8f225c0
remove more anys to appease format gods
LouiseHsu Sep 27, 2024
2c6efdb
Merge branch 'main' into iap_add_purchase
LouiseHsu Sep 27, 2024
72ce51c
a lil bit of refactioring
LouiseHsu Oct 1, 2024
2e940fe
Merge branch 'iap_add_purchase' of github.com:LouiseHsu/packages into…
LouiseHsu Oct 1, 2024
442c158
better error messages
LouiseHsu Oct 1, 2024
f48510b
some refactoring
LouiseHsu Oct 1, 2024
6076bf1
.
LouiseHsu Oct 1, 2024
d8dcad2
remove uneeded filed
LouiseHsu Oct 2, 2024
9c2893b
oops pathing
LouiseHsu Oct 2, 2024
1a74fb7
.
LouiseHsu Oct 2, 2024
1b688ae
.
LouiseHsu Oct 2, 2024
74c2de3
.
LouiseHsu Oct 4, 2024
71c9a1b
.
LouiseHsu Oct 4, 2024
582156b
no message
LouiseHsu Oct 4, 2024
e6bec70
.
LouiseHsu Oct 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
native tests are donesies
  • Loading branch information
LouiseHsu committed Sep 25, 2024
commit aeef979147b0392498bd7d2f840ee153b6e243db
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ extension InAppPurchasePlugin: InAppPurchase2API {
do {
let product = try await Product.products(for: [id]).first
guard let product = product else {
throw PigeonError(
let error = PigeonError(
code: "storekit2_failed_to_fetch_product", message: "Storekit has failed to fetch this product.",
details: "Storekit has failed to fetch this product.")
return completion(.failure(error))
}
let result = try await product.purchase()

let result = try await product.purchase(options: [])

switch result {
case .success(let verification):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@
"name" : "App Store Sync"
},
{
"current" : null,
"current" : {
"index" : 2,
"type" : "generic"
},
"enabled" : false,
"name" : "Subscription Status"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ final class InAppPurchase2PluginTests: XCTestCase {
session = try! SKTestSession(configurationFileNamed: "Configuration")
session.resetToDefaultState()
session.clearTransactions()
print("deleting")
session.disableDialogs = true
let receiptManagerStub = FIAPReceiptManagerStub()
plugin = InAppPurchasePluginStub(receiptManager: receiptManagerStub) { request in

plugin = InAppPurchasePluginStub(receiptManager: FIAPReceiptManagerStub()) { request in
DefaultRequestHandler(requestHandler: FIAPRequestHandler(request: request))
}
try plugin.startListeningToTransactions()
Expand Down Expand Up @@ -126,9 +125,6 @@ final class InAppPurchase2PluginTests: XCTestCase {
}
}
await fulfillment(of: [expectation], timeout: 5)

// Reset test session
// try await session.setSimulatedError(nil, forAPI: .loadProducts)
}

func testSuccessfulPurchase() async throws {
Expand Down Expand Up @@ -165,10 +161,46 @@ final class InAppPurchase2PluginTests: XCTestCase {
}
}
await fulfillment(of: [expectation], timeout: 5)
// try await session.setSimulatedError(nil, forAPI: .loadProducts)
}

func testDiscountedSubscriptionSuccess() async throws {
@available(iOS 17.0, *)
func testFailedProductUnavilablePurchase() async throws {
try await session.setSimulatedError(
.purchase(.productUnavailable), forAPI: .purchase)
let expectation = self.expectation(description: "Purchase request should succeed")
plugin.purchase(
id: "consumable", options: nil
) { result in
switch result {
case .success(_):
XCTFail("Purchase should NOT suceed.")
case .failure(let error):
XCTAssertEqual(error.localizedDescription, "Item Unavailable")
expectation.fulfill()
}
}
await fulfillment(of: [expectation], timeout: 5)
}

func testInvalidProductPurchase() async throws {
let expectation = self.expectation(description: "products request should fail")
plugin.purchase(
id: "invalid_product", options: nil
) { result in
switch result {
case .success(_):
XCTFail("Purchase should NOT suceed.")
case .failure(let error):
let pigeonError = error as! PigeonError;

XCTAssertEqual(pigeonError.code, "storekit2_failed_to_fetch_product")
expectation.fulfill()
}
}
await fulfillment(of: [expectation], timeout: 5)
}

func testPurchaseUpgradeConsumableSuccess() async throws {
let expectation = self.expectation(description: "Purchase request should succeed")
plugin.purchase(
id: "subscription_discounted", options: nil
Expand All @@ -185,10 +217,10 @@ final class InAppPurchase2PluginTests: XCTestCase {
await fulfillment(of: [expectation], timeout: 5)
}

func testDiscountedProductSuccess() async throws {
func testDiscountedSubscriptionSuccess() async throws {
let expectation = self.expectation(description: "Purchase request should succeed")
plugin.purchase(
id: "consumable_discounted", options: nil
id: "subscription_discounted", options: nil
) { result in
switch result {
case .success(let purchaseResult):
Expand All @@ -202,24 +234,20 @@ final class InAppPurchase2PluginTests: XCTestCase {
await fulfillment(of: [expectation], timeout: 5)
}

@available(iOS 17.0, *)
func testPurchaseFailureReturnsCorrectError() async throws {
try await session.setSimulatedError(
.purchase(.productUnavailable), forAPI: .purchase)
func testDiscountedProductSuccess() async throws {
let expectation = self.expectation(description: "Purchase request should succeed")
plugin.purchase(
id: "consumable", options: nil
id: "consumable_discounted", options: nil
) { result in
switch result {
case .success(_):
XCTFail("Purchase should NOT suceed.")
case .failure(let error):
XCTAssertEqual(error.localizedDescription, "Item Unavailable")
case .success(let purchaseResult):
print("Purchase successful: \(purchaseResult)")
expectation.fulfill()

case .failure(let error):
XCTFail("Purchase should NOT fail. Failed with \(error)")
}
}
await fulfillment(of: [expectation], timeout: 5)
// try await session.setSimulatedError(
// nil, forAPI: .purchase)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ class FakeStoreKit2Platform implements TestInAppPurchase2Api {
late Set<String> validProductIDs;
late Map<String, SK2Product> validProducts;
PlatformException? queryProductException;
bool isListenerRegistered = false;

void reset() {
validProductIDs = <String>{'123', '456'};
Expand Down Expand Up @@ -331,28 +332,26 @@ class FakeStoreKit2Platform implements TestInAppPurchase2Api {
@override
Future<SK2ProductPurchaseResultMessage> purchase(String id,
{SK2ProductPurchaseOptionsMessage? options}) {
return SK2ProductPurchaseResultMessage.
return Future<SK2ProductPurchaseResultMessage>.value(SK2ProductPurchaseResultMessage.success);
}

@override
Future<void> finish(int id) {
// TODO: implement finish
throw UnimplementedError();
return Future<void>.value();
}

@override
Future<List<SK2TransactionMessage?>> transactions() {
// TODO: implement transactions
throw UnimplementedError();
return
Future<List<SK2TransactionMessage?>>.value([SK2TransactionMessage(id: 123, originalId: 123, productId: "product_id", purchaseDate: "12-12")]);
}

@override
void startListeningToTransactions() {
// TODO: implement startListeningToTransactions
isListenerRegistered = true;
}

@override
void stopListeningToTransactions() {
// TODO: implement stopListeningToTransactions
}
isListenerRegistered = false; }
}