generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for
TbdexOrderInstructionsNotifier
(#325)
- Loading branch information
1 parent
e5ce33b
commit 459c1f1
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
test/features/tbdex/tbdex_order_instructions_notifier_test.dart
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,75 @@ | ||
import 'package:didpay/features/did/did_provider.dart'; | ||
import 'package:didpay/features/tbdex/tbdex_order_instructions_notifier.dart'; | ||
import 'package:didpay/features/tbdex/tbdex_service.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
|
||
import '../../helpers/mocks.dart'; | ||
import '../../helpers/riverpod_helpers.dart'; | ||
import '../../helpers/test_data.dart'; | ||
|
||
Future<void> main() async { | ||
await TestData.initializeDids(); | ||
|
||
final did = TestData.aliceDid; | ||
const pfiDid = '123'; | ||
const exchangeId = 'rfq_01ha835rhefwmagsknrrhvaa0k'; | ||
|
||
group('TbdexOrderInstructionsNotifier`', () { | ||
group('startPolling', () { | ||
test('should return OrderInstructions if successful', () async { | ||
final mockTbdexService = MockTbdexService(); | ||
final orderInstruction = TestData.getOrderInstructions(); | ||
|
||
when(() => mockTbdexService.getExchange(did, pfiDid, exchangeId)) | ||
.thenAnswer((_) async => [orderInstruction]); | ||
|
||
final container = createContainer( | ||
overrides: [ | ||
tbdexServiceProvider.overrideWith( | ||
(ref) => mockTbdexService, | ||
), | ||
didProvider.overrideWith((ref) => did), | ||
], | ||
); | ||
|
||
final tbdexOrderInstructionsNotifier = | ||
container.read(orderInstructionsProvider.notifier); | ||
|
||
final result = await tbdexOrderInstructionsNotifier.startPolling( | ||
pfiDid, | ||
exchangeId, | ||
); | ||
|
||
expect(result, orderInstruction); | ||
}); | ||
|
||
test('should throw an Exception if not successful', () async { | ||
final mockTbdexService = MockTbdexService(); | ||
|
||
when(() => mockTbdexService.getExchange(did, pfiDid, exchangeId)) | ||
.thenThrow(Exception('Error')); | ||
|
||
final container = createContainer( | ||
overrides: [ | ||
tbdexServiceProvider.overrideWith( | ||
(ref) => mockTbdexService, | ||
), | ||
didProvider.overrideWith((ref) => did), | ||
], | ||
); | ||
|
||
final tbdexOrderInstructionsNotifier = | ||
container.read(orderInstructionsProvider.notifier); | ||
|
||
expect( | ||
() => tbdexOrderInstructionsNotifier.startPolling( | ||
pfiDid, | ||
exchangeId, | ||
), | ||
throwsA(isA<Exception>()), | ||
); | ||
}); | ||
}); | ||
}); | ||
} |
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