-
-
Notifications
You must be signed in to change notification settings - Fork 541
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add integration test infrastructure (#62)
* WIP: add integration test infrastructure * fix env-files.sh * fix working directory * debug * try different ip method * try different IP method * try different IP method * start Android emulator * start Android emulator * fix analyze issue, cleanup * increase timeout * create payment method integration test * integrate native instrumentation for android this is needed to run it on firebase * add ios native configuration this is needed to run the test on firebase * feat: payment method tests * fix: remane integration test job * fix indent worflow file * fix isEmpty fields * hide app_test.dart test * fix test * fix unit tests * try to fix workflow * fix action * run it on macos-latest * update tests, cleanup * update tests, cleanup Co-authored-by: Remon <[email protected]> Co-authored-by: Jaime Blasco <[email protected]> Co-authored-by: Rémon <[email protected]>
- Loading branch information
1 parent
3339623
commit 416d9df
Showing
19 changed files
with
664 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
22 changes: 22 additions & 0 deletions
22
example/android/app/src/androidTest/java/com/flutter/stripe/example/BridgeTest.kt
This file contains 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,22 @@ | ||
import com.facebook.react.bridge.ReadableMap | ||
import org.junit.Test | ||
|
||
class BridgeTest { | ||
|
||
@Test | ||
fun testGetDouble() { | ||
val map = ReadableMap(mapOf("test" to 1.1)) | ||
assert(map.getDouble("test") == 1.1) | ||
} | ||
@Test | ||
fun testGetIntShouldFail() { | ||
val map = ReadableMap(mapOf("test" to 1.1)) | ||
var exception: Exception? = null | ||
try { | ||
map.getInt("test") | ||
} catch (e: Exception) { | ||
exception = e | ||
} | ||
assert(exception!!.message == "We've got a double here") | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
example/android/app/src/androidTest/java/com/flutter/stripe/example/MainActivityTest.kt
This file contains 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,16 @@ | ||
package com.flutter.stripe.example | ||
|
||
import androidx.test.rule.ActivityTestRule | ||
import com.facebook.react.bridge.ReadableMap | ||
import dev.flutter.plugins.integration_test.FlutterTestRunner | ||
import org.json.JSONObject | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(FlutterTestRunner::class) | ||
class MainActivityTest { | ||
@get:Rule | ||
var rule: ActivityTestRule<MainActivity> = | ||
ActivityTestRule(MainActivity::class.java, true, false) | ||
} |
This file contains 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,121 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_stripe/flutter_stripe.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:http/http.dart' as http; | ||
import 'package:integration_test/integration_test.dart'; | ||
|
||
import '.env.dart'; | ||
import 'ip.dart'; | ||
|
||
void main() { | ||
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
Stripe.publishableKey = stripePublishableKey; | ||
Stripe.merchantIdentifier = 'MerchantIdentifier'; | ||
Stripe.urlScheme = 'flutterstripe'; | ||
|
||
group('Payment sheet', () { | ||
testWidgets('init payment sheet', (_) async { | ||
// 1. create payment intent on the server | ||
final _paymentSheetData = await _createTestPaymentSheet(); | ||
|
||
// 2. initialize the payment sheet | ||
await Stripe.instance.initPaymentSheet( | ||
paymentSheetParameters: SetupPaymentSheetParameters( | ||
applePay: true, | ||
googlePay: true, | ||
style: ThemeMode.dark, | ||
testEnv: true, | ||
merchantCountryCode: 'DE', | ||
merchantDisplayName: 'Flutter Stripe Store Demo', | ||
customerId: _paymentSheetData['customer'], | ||
paymentIntentClientSecret: _paymentSheetData['paymentIntent'], | ||
customerEphemeralKeySecret: _paymentSheetData['ephemeralKey'], | ||
), | ||
); | ||
|
||
expect(true, _paymentSheetData['paymentIntent'] != null); | ||
}); | ||
}); | ||
|
||
group('Create payment method', () { | ||
testWidgets('create payment method', (tester) async { | ||
// 1. create some billing details | ||
final billingDetails = BillingDetails( | ||
name: 'Name', | ||
email: '[email protected]', | ||
phone: '+48888000888', | ||
address: Address( | ||
city: 'Houston', | ||
country: 'US', | ||
line1: '1459 Circle Drive', | ||
line2: '', | ||
state: 'Texas', | ||
postalCode: '77063', | ||
), | ||
); | ||
|
||
// 2. update card details | ||
// because of https://github.com/flutter/flutter/issues/34345 | ||
// we cannot use cardfield | ||
final cardDetails = CardDetails( | ||
number: '4242424242424242', | ||
cvc: '424', | ||
expirationMonth: 04, | ||
expirationYear: 2025, | ||
); | ||
await Stripe.instance.dangerouslyUpdateCardDetails(cardDetails); | ||
|
||
final paymentMethod = await Stripe.instance.createPaymentMethod( | ||
PaymentMethodParams.card( | ||
paymentMethodData: PaymentMethodData( | ||
billingDetails: billingDetails, | ||
), | ||
), | ||
); | ||
|
||
// 3. create intent on the server | ||
final paymentIntentResult = await _createNoWebhookPayEndpointMethod(paymentMethod.id); | ||
expect(paymentIntentResult['status'], 'succeeded'); | ||
}); | ||
}); | ||
} | ||
|
||
Future<Map<String, dynamic>> _createTestPaymentSheet() async { | ||
// ifconfig | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $2}' could return multiple IPs, divided by new line - use the last one | ||
final ipAddress = kApiUrl.split('\n').last.trim(); | ||
print('IP Address of the server: $ipAddress'); | ||
final url = Uri.parse('http://$ipAddress:4242/payment-sheet'); | ||
final response = await http.post( | ||
url, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: json.encode({ | ||
'a': 'a', | ||
}), | ||
); | ||
return json.decode(response.body); | ||
} | ||
|
||
Future<Map<String, dynamic>> _createNoWebhookPayEndpointMethod(String paymentMethodId) async { | ||
final ipAddress = kApiUrl.split('\n').last.trim(); | ||
final url = Uri.parse('http://$ipAddress:4242/pay-without-webhooks'); | ||
final response = await http.post( | ||
url, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: json.encode({ | ||
'useStripeSdk': true, | ||
'paymentMethodId': paymentMethodId, | ||
'currency': 'usd', | ||
'items': [ | ||
{'id': 'id'} | ||
] | ||
}), | ||
); | ||
return json.decode(response.body); | ||
} |
This file contains 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 @@ | ||
const kApiUrl = '''192.168.0.1'''; |
Oops, something went wrong.