From 999b762e71d4624819ee98f00b0d7b9cf7100dc5 Mon Sep 17 00:00:00 2001 From: Oscar Date: Thu, 23 Nov 2023 14:47:02 +0100 Subject: [PATCH] feat: questions repository (#12) Co-authored-by: Rui Miguel Alonso Co-authored-by: Erick --- .github/workflows/questions_repository.yaml | 22 ++++++++++++ .../api_client/test/src/api_client_test.dart | 2 -- .../src/widgets/animated_sprite_test.dart | 1 - packages/questions_repository/.gitignore | 7 ++++ packages/questions_repository/README.md | 12 +++++++ .../analysis_options.yaml | 1 + .../questions_repository/coverage_badge.svg | 20 +++++++++++ .../lib/questions_repository.dart | 4 +++ .../lib/src/questions_repository.dart | 16 +++++++++ packages/questions_repository/pubspec.yaml | 16 +++++++++ .../test/src/questions_repository_test.dart | 35 +++++++++++++++++++ 11 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/questions_repository.yaml create mode 100644 packages/questions_repository/.gitignore create mode 100644 packages/questions_repository/README.md create mode 100644 packages/questions_repository/analysis_options.yaml create mode 100644 packages/questions_repository/coverage_badge.svg create mode 100644 packages/questions_repository/lib/questions_repository.dart create mode 100644 packages/questions_repository/lib/src/questions_repository.dart create mode 100644 packages/questions_repository/pubspec.yaml create mode 100644 packages/questions_repository/test/src/questions_repository_test.dart 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/api_client/test/src/api_client_test.dart b/packages/api_client/test/src/api_client_test.dart index 192624d..ac71c37 100644 --- a/packages/api_client/test/src/api_client_test.dart +++ b/packages/api_client/test/src/api_client_test.dart @@ -1,5 +1,3 @@ -// ignore_for_file: prefer_const_constructors - import 'dart:async'; import 'dart:io'; diff --git a/packages/app_ui/test/src/widgets/animated_sprite_test.dart b/packages/app_ui/test/src/widgets/animated_sprite_test.dart index 6df14a0..93eec8a 100644 --- a/packages/app_ui/test/src/widgets/animated_sprite_test.dart +++ b/packages/app_ui/test/src/widgets/animated_sprite_test.dart @@ -1,4 +1,3 @@ -// ignore_for_file: prefer_const_constructors import 'dart:ui' as ui show Image; import 'package:app_ui/app_ui.dart'; diff --git a/packages/questions_repository/.gitignore b/packages/questions_repository/.gitignore new file mode 100644 index 0000000..526da15 --- /dev/null +++ b/packages/questions_repository/.gitignore @@ -0,0 +1,7 @@ +# See https://www.dartlang.org/guides/libraries/private-files + +# Files and directories created by pub +.dart_tool/ +.packages +build/ +pubspec.lock \ No newline at end of file diff --git a/packages/questions_repository/README.md b/packages/questions_repository/README.md new file mode 100644 index 0000000..99af6f2 --- /dev/null +++ b/packages/questions_repository/README.md @@ -0,0 +1,12 @@ +# Questions Repository + +[![style: very good analysis][very_good_analysis_badge]][very_good_analysis_link] +[![Powered by Mason](https://img.shields.io/endpoint?url=https%3A%2F%2Ftinyurl.com%2Fmason-badge)](https://github.com/felangel/mason) +[![License: MIT][license_badge]][license_link] + +Repository to access QuestionsResource through the Api Client. + +[license_badge]: https://img.shields.io/badge/license-MIT-blue.svg +[license_link]: https://opensource.org/licenses/MIT +[very_good_analysis_badge]: https://img.shields.io/badge/style-very_good_analysis-B22C89.svg +[very_good_analysis_link]: https://pub.dev/packages/very_good_analysis diff --git a/packages/questions_repository/analysis_options.yaml b/packages/questions_repository/analysis_options.yaml new file mode 100644 index 0000000..799268d --- /dev/null +++ b/packages/questions_repository/analysis_options.yaml @@ -0,0 +1 @@ +include: package:very_good_analysis/analysis_options.5.1.0.yaml diff --git a/packages/questions_repository/coverage_badge.svg b/packages/questions_repository/coverage_badge.svg new file mode 100644 index 0000000..499e98c --- /dev/null +++ b/packages/questions_repository/coverage_badge.svg @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + coverage + coverage + 100% + 100% + + diff --git a/packages/questions_repository/lib/questions_repository.dart b/packages/questions_repository/lib/questions_repository.dart new file mode 100644 index 0000000..b569d36 --- /dev/null +++ b/packages/questions_repository/lib/questions_repository.dart @@ -0,0 +1,4 @@ +/// Repository to access QuestionsResource from the Api Client. +library questions_repository; + +export 'src/questions_repository.dart'; diff --git a/packages/questions_repository/lib/src/questions_repository.dart b/packages/questions_repository/lib/src/questions_repository.dart new file mode 100644 index 0000000..7d7d0f2 --- /dev/null +++ b/packages/questions_repository/lib/src/questions_repository.dart @@ -0,0 +1,16 @@ +import 'package:api_client/api_client.dart'; + +/// {@template questions_repository} +/// Repository to access QuestionsResource from the Api Client. +/// {@endtemplate} +class QuestionsRepository { + /// {@macro questions_repository} + const QuestionsRepository(this._questionsResource); + + final QuestionsResource _questionsResource; + + /// Returns [VertexResponse] based on a query. + Future getVertexResponse(String query) async { + return _questionsResource.getVertexResponse(query); + } +} diff --git a/packages/questions_repository/pubspec.yaml b/packages/questions_repository/pubspec.yaml new file mode 100644 index 0000000..caa4eba --- /dev/null +++ b/packages/questions_repository/pubspec.yaml @@ -0,0 +1,16 @@ +name: questions_repository +description: Repository to access QuestionsResource through the Api Client. +version: 0.1.0+1 +publish_to: none + +environment: + sdk: ">=3.1.0 <4.0.0" + +dependencies: + api_client: + path: ../api_client + +dev_dependencies: + mocktail: ^1.0.0 + test: ^1.19.2 + very_good_analysis: ^5.1.0 diff --git a/packages/questions_repository/test/src/questions_repository_test.dart b/packages/questions_repository/test/src/questions_repository_test.dart new file mode 100644 index 0000000..08cd139 --- /dev/null +++ b/packages/questions_repository/test/src/questions_repository_test.dart @@ -0,0 +1,35 @@ +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', () { + 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()), + ); + }); + }); + }); +}