Skip to content

Commit

Permalink
feat: get render mode info from firestore (#100)
Browse files Browse the repository at this point in the history
* feat: get render mode info from firestore

* feat: update method to use several limits
  • Loading branch information
B0berman authored Mar 21, 2024
1 parent e384199 commit c1a0e56
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/board_info_repository/lib/src/board_info_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class BoardInfoRepository {
/// The [CollectionReference] for the config.
late final CollectionReference<Map<String, dynamic>> boardInfoCollection;

/// Return the total words count available in the crossword.
/// Returns the total words count available in the crossword.
Future<int> getTotalWordsCount() async {
try {
final results = await boardInfoCollection
Expand All @@ -48,7 +48,7 @@ class BoardInfoRepository {
}
}

/// Return the solved words count in the crossword.
/// Returns the solved words count in the crossword.
Future<int> getSolvedWordsCount() async {
try {
final results = await boardInfoCollection
Expand All @@ -61,4 +61,17 @@ class BoardInfoRepository {
throw BoardInfoException(error, stackStrace);
}
}

/// Returns the limit at which the render mode should switch
Future<List<double>> getRenderModeZoomLimits() async {
try {
final results = await boardInfoCollection
.where('type', isEqualTo: 'render_mode_limit')
.get();

return results.docs.map((e) => e.data()['value'] as double).toList();
} catch (error, stackStrace) {
throw BoardInfoException(error, stackStrace);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ void main() {
when(
() => collection.where('type', isEqualTo: 'solved_words_count'),
).thenReturn(collection);
when(
() => collection.where('type', isEqualTo: 'render_mode_limit'),
).thenReturn(collection);

when(collection.get).thenAnswer((_) async => query);
when(() => query.docs).thenReturn([doc]);
Expand Down Expand Up @@ -87,6 +90,24 @@ void main() {
);
});
});

group('getRenderModeZoomLimit', () {
test('returns render mode limit from firebase', () async {
mockQueryResult(0.6);
final result = await boardInfoRepository.getRenderModeZoomLimits();
expect(result, equals([0.6]));
});

test('throws BoardInfoException when fetching the info fails', () {
when(
() => collection.where('type', isEqualTo: 'render_mode_limit'),
).thenThrow(Exception('oops'));
expect(
() => boardInfoRepository.getRenderModeZoomLimits(),
throwsA(isA<BoardInfoException>()),
);
});
});
});

group('BoardInfoException', () {
Expand Down

0 comments on commit c1a0e56

Please sign in to comment.