Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

test: add tests for TbdexQuoteNotifier #321

Merged
merged 4 commits into from
Oct 24, 2024
Merged
Changes from all commits
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
68 changes: 68 additions & 0 deletions test/features/tbdex/tbdex_quote_notifier_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import 'package:didpay/features/did/did_provider.dart';
import 'package:didpay/features/tbdex/tbdex_quote_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('TbdexQuoteNotifier`', () {
group('startPolling', () {
test('should return Quote if successful', () async {
final mockTbdexService = MockTbdexService();
final quote = TestData.getQuote();

when(() => mockTbdexService.getExchange(did, pfiDid, exchangeId))
.thenAnswer((_) async => [quote]);

final container = createContainer(
overrides: [
tbdexServiceProvider.overrideWith(
(ref) => mockTbdexService,
),
didProvider.overrideWith((ref) => did),
],
);

final tbdexQuoteNotifier = container.read(quoteProvider.notifier);

final result =
await tbdexQuoteNotifier.startPolling(pfiDid, exchangeId);

expect(result, quote);
});

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 tbdexQuoteNotifier = container.read(quoteProvider.notifier);

expect(
() => tbdexQuoteNotifier.startPolling(pfiDid, exchangeId),
throwsA(isA<Exception>()),
);
});
});
});
}
Loading