From 528b3a501c37a35407084b44ad858b1dec0b31a7 Mon Sep 17 00:00:00 2001 From: Oscar Date: Wed, 22 Nov 2023 16:50:27 +0100 Subject: [PATCH] test: coverage --- .github/workflows/questions_repository.yaml | 22 ++++++++++++++ .../lib/src/questions_repository.dart | 1 + .../test/src/questions_repository_test.dart | 29 +++++++++++++++++-- 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/questions_repository.yaml diff --git a/.github/workflows/questions_repository.yaml b/.github/workflows/questions_repository.yaml new file mode 100644 index 0000000..a88764f --- /dev/null +++ b/.github/workflows/questions_repository.yaml @@ -0,0 +1,22 @@ +name: questions_repository + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: + push: + paths: + - "packages/questions_repository/**" + - ".github/workflows/questions_repository.yaml" + + pull_request: + paths: + - "packages/questions_repository/**" + - ".github/workflows/questions_repository.yaml" + +jobs: + build: + uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/dart_package.yml@v1 + with: + working_directory: packages/questions_repository \ No newline at end of file diff --git a/packages/questions_repository/lib/src/questions_repository.dart b/packages/questions_repository/lib/src/questions_repository.dart index 722d2fe..77a1863 100644 --- a/packages/questions_repository/lib/src/questions_repository.dart +++ b/packages/questions_repository/lib/src/questions_repository.dart @@ -9,6 +9,7 @@ class QuestionsRepository { final QuestionsResource _questionsResource; + /// Returns [VertexResponse] based on a query. Future getVertexResponse(String query) async { return _questionsResource.getVertexResponse(query); } diff --git a/packages/questions_repository/test/src/questions_repository_test.dart b/packages/questions_repository/test/src/questions_repository_test.dart index 1ad3f5c..3dd4ef0 100644 --- a/packages/questions_repository/test/src/questions_repository_test.dart +++ b/packages/questions_repository/test/src/questions_repository_test.dart @@ -1,11 +1,36 @@ // ignore_for_file: prefer_const_constructors +import 'package:api_client/api_client.dart'; +import 'package:mocktail/mocktail.dart'; import 'package:questions_repository/questions_repository.dart'; import 'package:test/test.dart'; +class _MockQuestionsResource extends Mock implements QuestionsResource {} + +class _FakeVertexResponse extends Fake implements VertexResponse {} + void main() { group('QuestionsRepository', () { - test('can be instantiated', () { - expect(QuestionsRepository(), isNotNull); + late QuestionsResource questionsResource; + late QuestionsRepository questionsRepository; + + setUp(() { + questionsResource = _MockQuestionsResource(); + questionsRepository = QuestionsRepository(questionsResource); + }); + + setUpAll(() { + registerFallbackValue(_FakeVertexResponse()); + }); + + group('getVertexResponse', () { + test('returns VertexResponse', () { + when(() => questionsResource.getVertexResponse(any())) + .thenAnswer((_) async => _FakeVertexResponse()); + expectLater( + questionsRepository.getVertexResponse(''), + completion(isA()), + ); + }); }); }); }