-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
98 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,45 @@ | ||
import 'package:easy_upi_payment/easy_upi_payment.dart'; | ||
import 'package:easy_upi_payment/src/easy_upi_payment_method_channel.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
import 'fake_data.dart'; | ||
|
||
void main() { | ||
// MethodChannelEasyUpiPayment platform = MethodChannelEasyUpiPayment(); | ||
// const MethodChannel channel = MethodChannel('easy_upi_payment'); | ||
// | ||
// TestWidgetsFlutterBinding.ensureInitialized(); | ||
// | ||
// setUp(() { | ||
// channel.setMockMethodCallHandler((MethodCall methodCall) async { | ||
// return '42'; | ||
// }); | ||
// }); | ||
// | ||
// tearDown(() { | ||
// channel.setMockMethodCallHandler(null); | ||
// }); | ||
// | ||
// test('getPlatformVersion', () async { | ||
// expect(await platform.getPlatformVersion(), '42'); | ||
// }); | ||
final MethodChannelEasyUpiPayment platform = MethodChannelEasyUpiPayment(); | ||
const MethodChannel channel = MethodChannel('easy_upi_payment'); | ||
|
||
TestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
tearDown(() { | ||
channel.setMockMethodCallHandler(null); | ||
}); | ||
|
||
group('startPayment with appropriate result', () { | ||
setUp(() { | ||
channel.setMockMethodCallHandler((MethodCall methodCall) async { | ||
return fakeTransactionDetailsModel.toMap(); | ||
}); | ||
}); | ||
|
||
test('startPayment', () async { | ||
expect(await platform.startPayment(fakeEasyUpiPaymentModel), fakeTransactionDetailsModel); | ||
}); | ||
}); | ||
|
||
group('startPayment with exception', () { | ||
final platformException = PlatformException(code: EasyUpiPaymentExceptionType.failedException.toString()); | ||
setUp(() { | ||
channel.setMockMethodCallHandler((MethodCall methodCall) async { | ||
return platformException; | ||
}); | ||
}); | ||
|
||
test('startPayment', () async { | ||
expect( | ||
() => platform.startPayment(fakeEasyUpiPaymentModel), | ||
throwsA(isA<EasyUpiPaymentException>()), | ||
); | ||
}); | ||
}); | ||
} |
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 |
---|---|---|
@@ -1,29 +1,28 @@ | ||
// import 'package:flutter_test/flutter_test.dart'; | ||
// import 'package:easy_upi_payment/easy_upi_payment.dart'; | ||
// import 'package:easy_upi_payment/easy_upi_payment_platform_interface.dart'; | ||
// import 'package:easy_upi_payment/easy_upi_payment_method_channel.dart'; | ||
// import 'package:plugin_platform_interface/plugin_platform_interface.dart'; | ||
// | ||
// class MockEasyUpiPaymentPlatform | ||
// with MockPlatformInterfaceMixin | ||
// implements EasyUpiPaymentPlatform { | ||
// | ||
// @override | ||
// Future<String?> getPlatformVersion() => Future.value('42'); | ||
// } | ||
// | ||
// void main() { | ||
// final EasyUpiPaymentPlatform initialPlatform = EasyUpiPaymentPlatform.instance; | ||
// | ||
// test('$MethodChannelEasyUpiPayment is the default instance', () { | ||
// expect(initialPlatform, isInstanceOf<MethodChannelEasyUpiPayment>()); | ||
// }); | ||
// | ||
// test('getPlatformVersion', () async { | ||
// EasyUpiPayment easyUpiPaymentPlugin = EasyUpiPayment(); | ||
// MockEasyUpiPaymentPlatform fakePlatform = MockEasyUpiPaymentPlatform(); | ||
// EasyUpiPaymentPlatform.instance = fakePlatform; | ||
// | ||
// expect(await easyUpiPaymentPlugin.getPlatformVersion(), '42'); | ||
// }); | ||
// } | ||
import 'package:easy_upi_payment/easy_upi_payment.dart'; | ||
import 'package:easy_upi_payment/src/easy_upi_payment_method_channel.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:plugin_platform_interface/plugin_platform_interface.dart'; | ||
|
||
import 'fake_data.dart'; | ||
|
||
class MockEasyUpiPaymentPlatform with MockPlatformInterfaceMixin implements EasyUpiPaymentPlatform { | ||
@override | ||
Future<TransactionDetailModel?> startPayment(EasyUpiPaymentModel easyUpiPaymentModel) { | ||
return Future.value(fakeTransactionDetailsModel); | ||
} | ||
} | ||
|
||
void main() { | ||
final EasyUpiPaymentPlatform initialPlatform = EasyUpiPaymentPlatform.instance; | ||
|
||
test('$MethodChannelEasyUpiPayment is the default instance', () { | ||
expect(initialPlatform, isInstanceOf<MethodChannelEasyUpiPayment>()); | ||
}); | ||
|
||
test('startPayment', () async { | ||
final MockEasyUpiPaymentPlatform fakePlatform = MockEasyUpiPaymentPlatform(); | ||
EasyUpiPaymentPlatform.instance = fakePlatform; | ||
|
||
expect(await fakePlatform.startPayment(fakeEasyUpiPaymentModel), fakeTransactionDetailsModel); | ||
}); | ||
} |
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 @@ | ||
import 'package:easy_upi_payment/easy_upi_payment.dart'; | ||
|
||
const fakeTransactionDetailsModel = TransactionDetailModel( | ||
transactionId: 'transactionId', | ||
responseCode: 'responseCode', | ||
approvalRefNo: 'approvalRefNo', | ||
transactionRefId: 'transactionRefId', | ||
amount: 'amount', | ||
); | ||
|
||
const fakeEasyUpiPaymentModel = EasyUpiPaymentModel( | ||
payeeVpa: 'payeeVpa', | ||
payeeName: 'payeeName', | ||
amount: 10.0, | ||
description: 'description', | ||
); |