Skip to content

Commit

Permalink
add additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xsahil03x committed Dec 24, 2024
1 parent 269b284 commit 5026fff
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 20 deletions.
42 changes: 22 additions & 20 deletions packages/stream_chat_persistence/test/mock_chat_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,57 @@ import 'package:stream_chat_persistence/src/dao/dao.dart';
import 'package:stream_chat_persistence/src/db/drift_chat_database.dart';

class MockChatDatabase extends Mock implements DriftChatDatabase {
UserDao? _userDao;

@override
UserDao get userDao => _userDao ??= MockUserDao();

ChannelDao? _channelDao;
UserDao? _userDao;

@override
ChannelDao get channelDao => _channelDao ??= MockChannelDao();

MessageDao? _messageDao;
ChannelDao? _channelDao;

@override
MessageDao get messageDao => _messageDao ??= MockMessageDao();

PinnedMessageDao? _pinnedMessageDao;
MessageDao? _messageDao;

@override
PinnedMessageDao get pinnedMessageDao =>
_pinnedMessageDao ??= MockPinnedMessageDao();

MemberDao? _memberDao;
PinnedMessageDao? _pinnedMessageDao;

@override
MemberDao get memberDao => _memberDao ??= MockMemberDao();

ReactionDao? _reactionDao;
MemberDao? _memberDao;

@override
ReactionDao get reactionDao => _reactionDao ??= MockReactionDao();

PinnedMessageReactionDao? _pinnedMessageReactionDao;
ReactionDao? _reactionDao;

@override
PinnedMessageReactionDao get pinnedMessageReactionDao =>
_pinnedMessageReactionDao ??= MockPinnedMessageReactionDao();

ReadDao? _readDao;
PinnedMessageReactionDao? _pinnedMessageReactionDao;

@override
ReadDao get readDao => _readDao ??= MockReadDao();

ChannelQueryDao? _channelQueryDao;
ReadDao? _readDao;

@override
ChannelQueryDao get channelQueryDao =>
_channelQueryDao ??= MockChannelQueryDao();

ConnectionEventDao? _connectionEventDao;
ChannelQueryDao? _channelQueryDao;

@override
ConnectionEventDao get connectionEventDao =>
_connectionEventDao ??= MockConnectionEventDao();
ConnectionEventDao? _connectionEventDao;

@override
PollDao get pollDao => _pollDao ??= MockPollDao();
PollDao? _pollDao;

@override
PollVoteDao get pollVoteDao => _pollVoteDao ??= MockPollVoteDao();
PollVoteDao? _pollVoteDao;

@override
Future<void> flush() => Future.value();
Expand Down Expand Up @@ -84,3 +82,7 @@ class MockReadDao extends Mock implements ReadDao {}
class MockChannelQueryDao extends Mock implements ChannelQueryDao {}

class MockConnectionEventDao extends Mock implements ConnectionEventDao {}

class MockPollDao extends Mock implements PollDao {}

class MockPollVoteDao extends Mock implements PollVoteDao {}
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,48 @@ void main() {
verify(() => mockDatabase.channelDao.updateChannels(channels)).called(1);
});

test('updatePolls', () async {
const name = 'testPollName';
final options = List.generate(3, (index) => PollOption(text: '$index'));
final polls =
List.generate(3, (index) => Poll(name: name, options: options));
when(() => mockDatabase.pollDao.updatePolls(polls))
.thenAnswer((_) => Future.value());

await client.updatePolls(polls);
verify(() => mockDatabase.pollDao.updatePolls(polls)).called(1);
});

test('deletePollsByIds', () async {
final pollIds = <String>['testPollId'];
when(() => mockDatabase.pollDao.deletePollsByIds(pollIds))
.thenAnswer((_) => Future.value());

await client.deletePollsByIds(pollIds);
verify(() => mockDatabase.pollDao.deletePollsByIds(pollIds)).called(1);
});

test('updatePollVotes', () async {
final pollVotes = List.generate(
3, (index) => PollVote(id: '$index', optionId: 'testOptionId$index'));
when(() => mockDatabase.pollVoteDao.updatePollVotes(pollVotes))
.thenAnswer((_) => Future.value());

await client.updatePollVotes(pollVotes);
verify(() => mockDatabase.pollVoteDao.updatePollVotes(pollVotes))
.called(1);
});

test('deletePollVotesByPollIds', () async {
final pollIds = <String>['testPollId'];
when(() => mockDatabase.pollVoteDao.deletePollVotesByPollIds(pollIds))
.thenAnswer((_) => Future.value());

await client.deletePollVotesByPollIds(pollIds);
verify(() => mockDatabase.pollVoteDao.deletePollVotesByPollIds(pollIds))
.called(1);
});

test('updateMembers', () async {
const cid = 'testCid';
final members = List.generate(3, (index) => Member());
Expand Down

0 comments on commit 5026fff

Please sign in to comment.