|
| 1 | +import 'package:didpay/features/did/did_provider.dart'; |
| 2 | +import 'package:didpay/features/tbdex/tbdex_order_instructions_notifier.dart'; |
| 3 | +import 'package:didpay/features/tbdex/tbdex_service.dart'; |
| 4 | +import 'package:flutter_test/flutter_test.dart'; |
| 5 | +import 'package:mocktail/mocktail.dart'; |
| 6 | + |
| 7 | +import '../../helpers/mocks.dart'; |
| 8 | +import '../../helpers/riverpod_helpers.dart'; |
| 9 | +import '../../helpers/test_data.dart'; |
| 10 | + |
| 11 | +Future<void> main() async { |
| 12 | + await TestData.initializeDids(); |
| 13 | + |
| 14 | + final did = TestData.aliceDid; |
| 15 | + const pfiDid = '123'; |
| 16 | + const exchangeId = 'rfq_01ha835rhefwmagsknrrhvaa0k'; |
| 17 | + |
| 18 | + group('TbdexOrderInstructionsNotifier`', () { |
| 19 | + group('startPolling', () { |
| 20 | + test('should return OrderInstructions if successful', () async { |
| 21 | + final mockTbdexService = MockTbdexService(); |
| 22 | + final orderInstruction = TestData.getOrderInstructions(); |
| 23 | + |
| 24 | + when(() => mockTbdexService.getExchange(did, pfiDid, exchangeId)) |
| 25 | + .thenAnswer((_) async => [orderInstruction]); |
| 26 | + |
| 27 | + final container = createContainer( |
| 28 | + overrides: [ |
| 29 | + tbdexServiceProvider.overrideWith( |
| 30 | + (ref) => mockTbdexService, |
| 31 | + ), |
| 32 | + didProvider.overrideWith((ref) => did), |
| 33 | + ], |
| 34 | + ); |
| 35 | + |
| 36 | + final tbdexOrderInstructionsNotifier = |
| 37 | + container.read(orderInstructionsProvider.notifier); |
| 38 | + |
| 39 | + final result = await tbdexOrderInstructionsNotifier.startPolling( |
| 40 | + pfiDid, |
| 41 | + exchangeId, |
| 42 | + ); |
| 43 | + |
| 44 | + expect(result, orderInstruction); |
| 45 | + }); |
| 46 | + |
| 47 | + test('should throw an Exception if not successful', () async { |
| 48 | + final mockTbdexService = MockTbdexService(); |
| 49 | + |
| 50 | + when(() => mockTbdexService.getExchange(did, pfiDid, exchangeId)) |
| 51 | + .thenThrow(Exception('Error')); |
| 52 | + |
| 53 | + final container = createContainer( |
| 54 | + overrides: [ |
| 55 | + tbdexServiceProvider.overrideWith( |
| 56 | + (ref) => mockTbdexService, |
| 57 | + ), |
| 58 | + didProvider.overrideWith((ref) => did), |
| 59 | + ], |
| 60 | + ); |
| 61 | + |
| 62 | + final tbdexOrderInstructionsNotifier = |
| 63 | + container.read(orderInstructionsProvider.notifier); |
| 64 | + |
| 65 | + expect( |
| 66 | + () => tbdexOrderInstructionsNotifier.startPolling( |
| 67 | + pfiDid, |
| 68 | + exchangeId, |
| 69 | + ), |
| 70 | + throwsA(isA<Exception>()), |
| 71 | + ); |
| 72 | + }); |
| 73 | + }); |
| 74 | + }); |
| 75 | +} |
0 commit comments