Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add tests for TbdexQuoteNotifier #321

Merged
merged 4 commits into from
Oct 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions test/features/tbdex/tbdex_quote_notifier_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import '../../helpers/mocks.dart';
import '../../helpers/test_data.dart';

void main() async {
late MockTbdexService mockTbdexService;
late MockTbdexQuoteNotifier mockTbdexQuoteNotifier;

await TestData.initializeDids();

setUpAll(() {
registerFallbackValue(MockBearerDid());
registerFallbackValue(TestData.aliceDid);
});

setUp(() {
mockTbdexService = MockTbdexService();
mockTbdexQuoteNotifier = MockTbdexQuoteNotifier();

when(() => mockTbdexService.getExchange(any(), any(), any()))
.thenAnswer((_) async => TestData.getExchange());
});

group('TbdexQuoteNotifier Stress Tests', () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's rename this group to just TbdexQuoteNotifier

test('High-frequency polling with exponential backoff', () async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as #312 (comment)

when(() => mockTbdexQuoteNotifier.pollForQuote(any(), any()))
.thenAnswer((_) async => TestData.getQuote());

await mockTbdexQuoteNotifier.startPolling('pfiId', 'exchangeId');

verify(() => mockTbdexQuoteNotifier.startPolling('pfiId', 'exchangeId'))
.called(1);
});

test('Maximum retry attempts', () async {
when(() => mockTbdexQuoteNotifier.pollForQuote(any(), any()))
.thenThrow(Exception('Network error'));

await mockTbdexQuoteNotifier.startPolling('pfiId', 'exchangeId');

verify(() => mockTbdexQuoteNotifier.startPolling('pfiId', 'exchangeId'))
.called(1);
});

test('Handling network latency', () async {
when(() => mockTbdexQuoteNotifier.startPolling(any(), any()))
.thenAnswer((_) async {
await Future.delayed(const Duration(seconds: 5));
return TestData.getQuote();
});

await mockTbdexQuoteNotifier.startPolling('pfiId', 'exchangeId');

verify(() => mockTbdexQuoteNotifier.startPolling(any(), any())).called(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the reason we are using any() here in startPolling()?

});
});
}
Loading