diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner.xcodeproj/project.pbxproj b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner.xcodeproj/project.pbxproj index 2bb59d0ed32d..2526dafe6865 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner.xcodeproj/project.pbxproj +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner.xcodeproj/project.pbxproj @@ -27,8 +27,6 @@ 33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F22044A3C60003C045 /* Assets.xcassets */; }; 33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F42044A3C60003C045 /* MainMenu.xib */; }; 33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */; }; - F203876D2CBF302F000AF71F /* StoreKit2TranslatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F203876C2CBF302F000AF71F /* StoreKit2TranslatorTests.swift */; }; - F203876E2CBF302F000AF71F /* InAppPurchaseStoreKit2PluginTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F203876B2CBF302F000AF71F /* InAppPurchaseStoreKit2PluginTests.swift */; }; F24C45E42C409D87000C6C72 /* InAppPurchasePluginTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F24C45E32C409D87000C6C72 /* InAppPurchasePluginTests.swift */; }; F27694092C4724B200277144 /* ProductRequestHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F27694082C4724B200277144 /* ProductRequestHandlerTests.swift */; }; F27694132C49BF7B00277144 /* FIAPPaymentQueueDeleteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F27694122C49BF7B00277144 /* FIAPPaymentQueueDeleteTests.swift */; }; @@ -94,8 +92,6 @@ 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = ""; }; AEB2EC182EA43F26A351EE3E /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; B537BC9F2D936311267ABC65 /* Pods-RunnerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.debug.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.debug.xcconfig"; sourceTree = ""; }; - F203876B2CBF302F000AF71F /* InAppPurchaseStoreKit2PluginTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InAppPurchaseStoreKit2PluginTests.swift; sourceTree = ""; }; - F203876C2CBF302F000AF71F /* StoreKit2TranslatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreKit2TranslatorTests.swift; sourceTree = ""; }; F24C45E32C409D87000C6C72 /* InAppPurchasePluginTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = InAppPurchasePluginTests.swift; path = ../../shared/RunnerTests/InAppPurchasePluginTests.swift; sourceTree = ""; }; F27694082C4724B200277144 /* ProductRequestHandlerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ProductRequestHandlerTests.swift; path = ../../shared/RunnerTests/ProductRequestHandlerTests.swift; sourceTree = ""; }; F27694122C49BF7B00277144 /* FIAPPaymentQueueDeleteTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FIAPPaymentQueueDeleteTests.swift; path = ../../shared/RunnerTests/FIAPPaymentQueueDeleteTests.swift; sourceTree = ""; }; @@ -226,8 +222,6 @@ F700DD0328E652A10004836B /* RunnerTests */ = { isa = PBXGroup; children = ( - F203876B2CBF302F000AF71F /* InAppPurchaseStoreKit2PluginTests.swift */, - F203876C2CBF302F000AF71F /* StoreKit2TranslatorTests.swift */, F2D527252C583C1C00C137C7 /* TranslatorTests.swift */, F2D5271D2C50645600C137C7 /* PaymentQueueTests.swift */, F27694182C49DBE800277144 /* FIATransactionCacheTests.swift */, @@ -479,8 +473,6 @@ F24C45E42C409D87000C6C72 /* InAppPurchasePluginTests.swift in Sources */, F79BDC1C2905FC3200E3999D /* Stubs.m in Sources */, F27694092C4724B200277144 /* ProductRequestHandlerTests.swift in Sources */, - F203876D2CBF302F000AF71F /* StoreKit2TranslatorTests.swift in Sources */, - F203876E2CBF302F000AF71F /* InAppPurchaseStoreKit2PluginTests.swift in Sources */, F2C3A7412BD9D33D000D35F2 /* Stubs.swift in Sources */, F2D527262C583C1C00C137C7 /* TranslatorTests.swift in Sources */, F27694192C49DBE800277144 /* FIATransactionCacheTests.swift in Sources */, diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/InAppPurchaseStoreKit2PluginTests.swift b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/InAppPurchaseStoreKit2PluginTests.swift deleted file mode 100644 index c2fcfbdfedf0..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/InAppPurchaseStoreKit2PluginTests.swift +++ /dev/null @@ -1,229 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import StoreKitTest -import XCTest - -@testable import in_app_purchase_storekit - -@available(iOS 15.0, macOS 12.0, *) - -final class InAppPurchase2PluginTests: XCTestCase { - private var session: SKTestSession! - private var plugin: InAppPurchasePlugin! - - override func setUp() async throws { - try await super.setUp() - - session = try! SKTestSession(configurationFileNamed: "Configuration") - session.resetToDefaultState() - session.clearTransactions() - session.disableDialogs = true - - plugin = InAppPurchasePluginStub(receiptManager: FIAPReceiptManagerStub()) { request in - DefaultRequestHandler(requestHandler: FIAPRequestHandler(request: request)) - } - try plugin.startListeningToTransactions() - } - - override func tearDown() async throws { - self.session.clearTransactions() - session.disableDialogs = false - } - - func testCanMakePayments() throws { - let result = try plugin.canMakePayments() - XCTAssertTrue(result) - } - - func testGetProducts() async throws { - let expectation = self.expectation(description: "products successfully fetched") - - var fetchedProductMsg: SK2ProductMessage? - plugin.products(identifiers: ["subscription_silver"]) { result in - switch result { - case .success(let productMessages): - fetchedProductMsg = productMessages.first - expectation.fulfill() - case .failure(let error): - print("Failed to fetch products: \(error.localizedDescription)") - } - } - await fulfillment(of: [expectation], timeout: 5) - - let testProduct = try await Product.products(for: ["subscription_silver"]).first - - let testProductMsg = testProduct?.convertToPigeon - - XCTAssertNotNil(fetchedProductMsg) - XCTAssertEqual(testProductMsg, fetchedProductMsg) - } - - func testGetDiscountedProducts() async throws { - let expectation = self.expectation(description: "products successfully fetched") - - var fetchedProductMsg: SK2ProductMessage? - plugin.products(identifiers: ["subscription_silver"]) { result in - switch result { - case .success(let productMessages): - fetchedProductMsg = productMessages.first - expectation.fulfill() - case .failure(let error): print("Failed to fetch products: \(error.localizedDescription)") - } - } - await fulfillment(of: [expectation], timeout: 5) - - let testProduct = try await Product.products(for: ["subscription_silver"]).first - - let testProductMsg = testProduct?.convertToPigeon - - XCTAssertNotNil(fetchedProductMsg) - XCTAssertEqual(testProductMsg, fetchedProductMsg) - } - - func testGetInvalidProducts() async throws { - let expectation = self.expectation(description: "products successfully fetched") - - var fetchedProductMsg: [SK2ProductMessage]? - plugin.products(identifiers: ["invalid_product"]) { result in - switch result { - case .success(let productMessages): - fetchedProductMsg = productMessages - expectation.fulfill() - case .failure(_): - XCTFail("Products should be successfully fetched") - } - } - await fulfillment(of: [expectation], timeout: 5) - - XCTAssert(fetchedProductMsg?.count == 0) - } - - //TODO(louisehsu): Add testing for lower versions. - @available(iOS 17.0, macOS 14.0, *) - func testGetProductsWithStoreKitError() async throws { - try await session.setSimulatedError( - .generic(.networkError(URLError(.badURL))), forAPI: .loadProducts) - - let expectation = self.expectation(description: "products request should fail") - - plugin.products(identifiers: ["subscription_silver"]) { result in - switch result { - case .success(_): - XCTFail("This `products` call should not succeed") - case .failure(let error): - expectation.fulfill() - XCTAssert( - error.localizedDescription - == "The operation couldn’t be completed. (in_app_purchase_storekit.PigeonError error 1.)" - ) - } - } - await fulfillment(of: [expectation], timeout: 5) - } - - func testSuccessfulPurchase() async throws { - let expectation = self.expectation(description: "Purchase request should succeed") - plugin.purchase(id: "consumable", options: nil) { result in - switch result { - case .success(let purchaseResult): - expectation.fulfill() - case .failure(let error): - XCTFail("Purchase should NOT fail. Failed with \(error)") - } - } - await fulfillment(of: [expectation], timeout: 5) - } - - @available(iOS 17.0, macOS 14.0, *) - func testFailedNetworkErrorPurchase() async throws { - try await session.setSimulatedError( - .generic(.networkError(URLError(.badURL))), forAPI: .loadProducts) - let expectation = self.expectation(description: "products request should fail") - plugin.purchase(id: "consumable", options: nil) { result in - switch result { - case .success(_): - XCTFail("Purchase should NOT suceed.") - case .failure(let error): - XCTAssertEqual( - error.localizedDescription, - "The operation couldn’t be completed. (NSURLErrorDomain error -1009.)") - expectation.fulfill() - } - } - await fulfillment(of: [expectation], timeout: 5) - } - - @available(iOS 17.0, macOS 14.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) { result in - switch result { - case .success(let purchaseResult): - expectation.fulfill() - case .failure(let error): - XCTFail("Purchase should NOT fail. Failed with \(error)") - } - } - await fulfillment(of: [expectation], timeout: 5) - } - - func testDiscountedSubscriptionSuccess() async throws { - let expectation = self.expectation(description: "Purchase request should succeed") - plugin.purchase(id: "subscription_discounted", options: nil) { result in - switch result { - case .success(let purchaseResult): - expectation.fulfill() - case .failure(let error): - XCTFail("Purchase should NOT fail. Failed with \(error)") - } - } - await fulfillment(of: [expectation], timeout: 5) - } - - func testDiscountedProductSuccess() async throws { - let expectation = self.expectation(description: "Purchase request should succeed") - plugin.purchase(id: "consumable_discounted", options: nil) { result in - switch result { - case .success(let purchaseResult): - expectation.fulfill() - case .failure(let error): - XCTFail("Purchase should NOT fail. Failed with \(error)") - } - } - await fulfillment(of: [expectation], timeout: 5) - } -} diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/StoreKit2TranslatorTests.swift b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/StoreKit2TranslatorTests.swift deleted file mode 100644 index 6fbd1f8444f0..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/StoreKit2TranslatorTests.swift +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import Foundation -import StoreKitTest -import XCTest - -@testable import in_app_purchase_storekit - -@available(iOS 15.0, macOS 12.0, *) -final class StoreKit2TranslatorTests: XCTestCase { - private var session: SKTestSession! - private var plugin: InAppPurchasePlugin! - private var product: Product! - - // This is transcribed from the Configuration.storekit file. - var productMessage: SK2ProductMessage = - SK2ProductMessage( - id: "subscription_silver", - displayName: "Subscription Silver", - description: "A lower level subscription.", - price: 4.99, - displayPrice: "$4.99", - type: SK2ProductTypeMessage.autoRenewable, - subscription: SK2SubscriptionInfoMessage( - promotionalOffers: [], - subscriptionGroupID: "D0FEE8D8", - subscriptionPeriod: SK2SubscriptionPeriodMessage( - value: 1, - unit: SK2SubscriptionPeriodUnitMessage.week)), - priceLocale: SK2PriceLocaleMessage(currencyCode: "USD", currencySymbol: "$")) - - override func setUp() async throws { - try await super.setUp() - - self.session = try! SKTestSession(configurationFileNamed: "Configuration") - self.session.clearTransactions() - let receiptManagerStub = FIAPReceiptManagerStub() - plugin = InAppPurchasePluginStub(receiptManager: receiptManagerStub) { request in - DefaultRequestHandler(requestHandler: FIAPRequestHandler(request: request)) - } - product = try await Product.products(for: ["subscription_silver"]).first! - - } - - func testPigeonConversionForProduct() async throws { - XCTAssertNotNil(product) - let pigeonMessage = product.convertToPigeon - XCTAssertEqual(pigeonMessage, productMessage) - } - - func testPigeonConversionForSubscriptionInfo() async throws { - guard let subscription = product.subscription else { - XCTFail("SubscriptionInfo should not be nil") - return - } - let pigeonMessage = subscription.convertToPigeon - XCTAssertEqual(pigeonMessage, productMessage.subscription) - } - - func testPigeonConversionForProductType() async throws { - let type = product.type - let pigeonMessage = type.convertToPigeon - XCTAssertEqual(pigeonMessage, productMessage.type) - } - - func testPigeonConversionForSubscriptionPeriod() async throws { - guard let period = product.subscription?.subscriptionPeriod else { - XCTFail("SubscriptionPeriod should not be nil") - return - } - let pigeonMessage = period.convertToPigeon - XCTAssertEqual(pigeonMessage, productMessage.subscription?.subscriptionPeriod) - } - - func testPigeonConversionForPriceLocale() async throws { - let locale = product.priceFormatStyle.locale - let pigeonMessage = locale.convertToPigeon - XCTAssertEqual(pigeonMessage, productMessage.priceLocale) - } -}