Skip to content

Commit

Permalink
feat: fetch section size as board info from firestore
Browse files Browse the repository at this point in the history
  • Loading branch information
B0berman committed Mar 21, 2024
1 parent 2c5a9d7 commit 11ae3f3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/board_info_repository/lib/src/board_info_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,18 @@ class BoardInfoRepository {
throw BoardInfoException(error, stackStrace);
}
}

/// Return the solved words count in the crossword.
Future<int> getSectionSize() async {
try {
final results = await boardInfoCollection
.where('type', isEqualTo: 'section_size')
.get();

final data = results.docs.first.data();
return data['value'] as int;
} catch (error, stackStrace) {
throw BoardInfoException(error, stackStrace);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,24 @@ void main() {
);
});
});

group('getSectionSize', () {
test('returns the section size value from firebase', () async {
mockQueryResult(66000);
final result = await boardInfoRepository.getSectionSize();
expect(result, equals(66000));
});

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

group('BoardInfoException', () {
Expand Down

0 comments on commit 11ae3f3

Please sign in to comment.