test(persistence): update tests after enabling foreign keys

This commit is contained in:
Dmitry Zhifarsky
2021-08-08 21:42:44 +03:00
parent 8adc38f8e4
commit 68311a6c6c
6 changed files with 278 additions and 98 deletions
@@ -61,12 +61,73 @@ void main() {
expect(updatedChannel.cid, cid); expect(updatedChannel.cid, cid);
expect(updatedChannel.type, type); expect(updatedChannel.type, type);
//Saving a dummy user
const userId = 'userId';
final dummyUser = User(id: userId);
await database.userDao.updateUsers([dummyUser]);
// Saving a dummy member
final dummyMember = Member(userId: userId, user: dummyUser);
await database.memberDao.updateMembers(cid, [dummyMember]);
// Should match the dummy member
final updatedMembers = await database.memberDao.getMembersByCid(cid);
expect(updatedMembers.length, 1);
expect(updatedMembers.first.userId, userId);
// Saving a dummy message
const messageId = 'messageId';
final dummyMessage = Message(id: messageId, user: dummyUser);
await database.messageDao.updateMessages(cid, [dummyMessage]);
// Should match the dummy message
final updatedMessages = await database.messageDao.getMessagesByCid(cid);
expect(updatedMessages.length, 1);
expect(updatedMessages.first.id, messageId);
// Saving a dummy read
final dummyRead = Read(lastRead: DateTime.now(), user: dummyUser);
await database.readDao.updateReads(cid, [dummyRead]);
// Should match the dummy read
final updatedReads = await database.readDao.getReadsByCid(cid);
expect(updatedReads.length, 1);
expect(updatedReads.first.user, dummyUser);
// Saving a dummy reaction
final dummyReaction =
Reaction(type: 'type', messageId: messageId, userId: userId);
await database.reactionDao.updateReactions([dummyReaction]);
// Should match the dummy reaction
final updatedReactions =
await database.reactionDao.getReactionsByUserId(messageId, userId);
expect(updatedReactions.length, 1);
expect(updatedReactions.first.messageId, messageId);
// Deleting the dummyChannel using cid // Deleting the dummyChannel using cid
await channelDao.deleteChannelByCids([cid]); await channelDao.deleteChannelByCids([cid]);
// Fetched channel Should be null // Fetched channel Should be null
final channel = await channelDao.getChannelByCid(cid); final channel = await channelDao.getChannelByCid(cid);
expect(channel, isNull); expect(channel, isNull);
// Fetched members for passed cid should be empty
final members = await database.memberDao.getMembersByCid(cid);
expect(members, isEmpty);
// Fetched messages for passed cid should be empty
final messages = await database.messageDao.getMessagesByCid(cid);
expect(messages, isEmpty);
// Fetched reads for passed cid should be empty
final reads = await database.readDao.getReadsByCid(cid);
expect(reads, isEmpty);
// Fetched readtions for passed message id and user id should be empty
final reactions =
await database.reactionDao.getReactionsByUserId(messageId, userId);
expect(reactions, isEmpty);
}); });
test('cids', () async { test('cids', () async {
@@ -18,6 +18,7 @@ void main() {
}); });
Future<List<Member>> _prepareTestData(String cid) async { Future<List<Member>> _prepareTestData(String cid) async {
final channels = [ChannelModel(cid: cid)];
final users = List.generate(3, (index) => User(id: 'testUserId$index')); final users = List.generate(3, (index) => User(id: 'testUserId$index'));
final memberList = List.generate( final memberList = List.generate(
3, 3,
@@ -34,12 +35,13 @@ void main() {
), ),
); );
await database.userDao.updateUsers(users); await database.userDao.updateUsers(users);
await database.channelDao.updateChannels(channels);
await memberDao.updateMembers(cid, memberList); await memberDao.updateMembers(cid, memberList);
return memberList; return memberList;
} }
test('getMembersByCid', () async { test('getMembersByCid', () async {
const cid = 'testCid'; const cid = 'test:Cid';
// Should be empty initially // Should be empty initially
final members = await memberDao.getMembersByCid(cid); final members = await memberDao.getMembersByCid(cid);
@@ -70,7 +72,7 @@ void main() {
}); });
test('updateMembers', () async { test('updateMembers', () async {
const cid = 'testCid'; const cid = 'test:Cid';
// Preparing test data // Preparing test data
final memberList = await _prepareTestData(cid); final memberList = await _prepareTestData(cid);
@@ -132,7 +134,7 @@ void main() {
}); });
test('deleteMemberByCids', () async { test('deleteMemberByCids', () async {
const cid = 'testCid'; const cid = 'test:Cid';
// Preparing test data // Preparing test data
final members = await _prepareTestData(cid); final members = await _prepareTestData(cid);
@@ -23,6 +23,7 @@ void main() {
bool mapAllThreadToFirstMessage = false, bool mapAllThreadToFirstMessage = false,
int count = 3, int count = 3,
}) async { }) async {
final channels = [ChannelModel(cid: cid)];
final users = List.generate(count, (index) => User(id: 'testUserId$index')); final users = List.generate(count, (index) => User(id: 'testUserId$index'));
final messages = List.generate( final messages = List.generate(
count, count,
@@ -98,13 +99,20 @@ void main() {
if (quoted) ...quotedMessages, if (quoted) ...quotedMessages,
if (threads) ...threadMessages if (threads) ...threadMessages
]; ];
final reaction = Reaction(
type: 'type',
messageId: allMessages.first.id,
user: users.first,
);
await database.userDao.updateUsers(users); await database.userDao.updateUsers(users);
await database.channelDao.updateChannels(channels);
await messageDao.updateMessages(cid, allMessages); await messageDao.updateMessages(cid, allMessages);
await database.reactionDao.updateReactions([reaction]);
return allMessages; return allMessages;
} }
test('deleteMessageByIds', () async { test('deleteMessageByIds', () async {
const cid = 'testCid'; const cid = 'test:Cid';
// Preparing test data // Preparing test data
final insertedMessages = await _prepareTestData(cid); final insertedMessages = await _prepareTestData(cid);
@@ -113,66 +121,112 @@ void main() {
final messages = await messageDao.getMessagesByCid(cid); final messages = await messageDao.getMessagesByCid(cid);
expect(messages.length, insertedMessages.length); expect(messages.length, insertedMessages.length);
final firstMessageId = messages.first.id;
// Fetched reactions list should have one reaction for given message id
final reactions = await database.reactionDao.getReactions(firstMessageId);
expect(reactions.length, 1);
// Deleting 2 messages from DB // Deleting 2 messages from DB
await messageDao.deleteMessageByIds( await messageDao.deleteMessageByIds(
['testMessageId${cid}0', 'testMessageId${cid}1'], [firstMessageId, 'testMessageId${cid}1'],
); );
// New fetched messages length should 2 less than the // New fetched messages length should 2 less than the
// previous fetched messages // previous fetched messages
final newMessages = await messageDao.getMessagesByCid(cid); final newMessages = await messageDao.getMessagesByCid(cid);
expect(newMessages.length, messages.length - 2); expect(newMessages.length, messages.length - 2);
// Reaction for the first message should be deleted too
final newReactions =
await database.reactionDao.getReactions(firstMessageId);
expect(newReactions, isEmpty);
}); });
group('deleteMessageByCids', () { group('deleteMessageByCids', () {
const cid1 = 'testCid1'; const cid1 = 'test:Cid1';
const cid2 = 'testCid2'; const cid2 = 'test:Cid2';
test('should delete all the messages of first channel', () async { test(
// Preparing test data 'should delete all the messages and reactions of first channel',
final cid1InsertedMessages = await _prepareTestData(cid1); () async {
final cid2InsertedMessages = await _prepareTestData(cid2); // Preparing test data
final cid1InsertedMessages = await _prepareTestData(cid1);
final cid2InsertedMessages = await _prepareTestData(cid2);
// Fetched message list should match the test message list length // Fetched message list should match the test message list length
final cid1Messages = await messageDao.getMessagesByCid(cid1); final cid1Messages = await messageDao.getMessagesByCid(cid1);
final cid2Messages = await messageDao.getMessagesByCid(cid2); final cid2Messages = await messageDao.getMessagesByCid(cid2);
expect(cid1Messages.length, cid1InsertedMessages.length); expect(cid1Messages.length, cid1InsertedMessages.length);
expect(cid2Messages.length, cid2InsertedMessages.length); expect(cid2Messages.length, cid2InsertedMessages.length);
// Deleting all the messages of cid1 // Fetched reactions list should have one reaction for given message id
await messageDao.deleteMessageByCids([cid1]); final cid1firstMessageId = cid1Messages.first.id;
final cid1Reactions =
await database.reactionDao.getReactions(cid1firstMessageId);
expect(cid1Reactions.length, 1);
// Fetched messages length of only cid1 should be empty // Deleting all the messages of cid1
final cid1FetchedMessages = await messageDao.getMessagesByCid(cid1); await messageDao.deleteMessageByCids([cid1]);
final cid2FetchedMessages = await messageDao.getMessagesByCid(cid2);
expect(cid1FetchedMessages, isEmpty);
expect(cid2FetchedMessages, isNotEmpty);
});
test('should delete all the messages of both channel', () async { // Fetched messages length of only cid1 should be empty
// Preparing test data final cid1FetchedMessages = await messageDao.getMessagesByCid(cid1);
final cid1InsertedMessages = await _prepareTestData(cid1); final cid2FetchedMessages = await messageDao.getMessagesByCid(cid2);
final cid2InsertedMessages = await _prepareTestData(cid2); expect(cid1FetchedMessages, isEmpty);
expect(cid2FetchedMessages, isNotEmpty);
// Fetched message list should match the test message list length // Reaction for the first message should be deleted too
final cid1Messages = await messageDao.getMessagesByCid(cid1); final cid1FetchedReactions =
final cid2Messages = await messageDao.getMessagesByCid(cid2); await database.reactionDao.getReactions(cid1firstMessageId);
expect(cid1Messages.length, cid1InsertedMessages.length); expect(cid1FetchedReactions, isEmpty);
expect(cid2Messages.length, cid2InsertedMessages.length); },
);
// Deleting all the messages of cid1 test(
await messageDao.deleteMessageByCids([cid1, cid2]); 'should delete all the messages and reactions of both channel',
() async {
// Preparing test data
final cid1InsertedMessages = await _prepareTestData(cid1);
final cid2InsertedMessages = await _prepareTestData(cid2);
// Fetched messages length of both cid1 and cid2 should be empty // Fetched message list should match the test message list length
final cid1FetchedMessages = await messageDao.getMessagesByCid(cid1); final cid1Messages = await messageDao.getMessagesByCid(cid1);
final cid2FetchedMessages = await messageDao.getMessagesByCid(cid2); final cid2Messages = await messageDao.getMessagesByCid(cid2);
expect(cid1FetchedMessages, isEmpty); expect(cid1Messages.length, cid1InsertedMessages.length);
expect(cid2FetchedMessages, isEmpty); expect(cid2Messages.length, cid2InsertedMessages.length);
});
// Fetched reactions list should have one reaction for given message id
final cid1FirstMessageId = cid1Messages.first.id;
final cid1Reactions =
await database.reactionDao.getReactions(cid1FirstMessageId);
expect(cid1Reactions.length, 1);
final cid2FirstMessageId = cid2Messages.first.id;
final cid2Reactions =
await database.reactionDao.getReactions(cid2FirstMessageId);
expect(cid2Reactions.length, 1);
// Deleting all the messages of cid1
await messageDao.deleteMessageByCids([cid1, cid2]);
// Fetched messages length of both cid1 and cid2 should be empty
final cid1FetchedMessages = await messageDao.getMessagesByCid(cid1);
final cid2FetchedMessages = await messageDao.getMessagesByCid(cid2);
expect(cid1FetchedMessages, isEmpty);
expect(cid2FetchedMessages, isEmpty);
// Reaction for the first message should be deleted too
final cid1FetchedReactions =
await database.reactionDao.getReactions(cid1FirstMessageId);
expect(cid1FetchedReactions, isEmpty);
final cid2FetchedReactions =
await database.reactionDao.getReactions(cid2FirstMessageId);
expect(cid2FetchedReactions, isEmpty);
},
);
}); });
test('getMessageById', () async { test('getMessageById', () async {
const cid = 'testCid'; const cid = 'test:Cid';
const id = 'testMessageId${cid}0'; const id = 'testMessageId${cid}0';
// Should be null initially // Should be null initially
@@ -190,7 +244,7 @@ void main() {
}); });
test('getThreadMessages', () async { test('getThreadMessages', () async {
const cid = 'testCid'; const cid = 'test:Cid';
// Messages should be empty initially // Messages should be empty initially
final messages = await messageDao.getThreadMessages(cid); final messages = await messageDao.getThreadMessages(cid);
@@ -209,7 +263,7 @@ void main() {
}); });
test('getThreadMessagesByParentId', () async { test('getThreadMessagesByParentId', () async {
const cid = 'testCid'; const cid = 'test:Cid';
const parentId = 'testMessageId${cid}0'; const parentId = 'testMessageId${cid}0';
// Messages should be empty initially // Messages should be empty initially
@@ -228,7 +282,7 @@ void main() {
}); });
test('getThreadMessagesByParentId along with pagination', () async { test('getThreadMessagesByParentId along with pagination', () async {
const cid = 'testCid'; const cid = 'test:Cid';
const parentId = 'testMessageId${cid}0'; const parentId = 'testMessageId${cid}0';
const options = PaginationParams( const options = PaginationParams(
limit: 15, limit: 15,
@@ -262,7 +316,7 @@ void main() {
}); });
test('getMessagesByCid', () async { test('getMessagesByCid', () async {
const cid = 'testCid'; const cid = 'test:Cid';
// Should be empty initially // Should be empty initially
final messages = await messageDao.getMessagesByCid(cid); final messages = await messageDao.getMessagesByCid(cid);
@@ -283,7 +337,7 @@ void main() {
}); });
test('getMessagesByCid along with quotedMessage', () async { test('getMessagesByCid along with quotedMessage', () async {
const cid = 'testCid'; const cid = 'test:Cid';
// Should be empty initially // Should be empty initially
final messages = await messageDao.getMessagesByCid(cid); final messages = await messageDao.getMessagesByCid(cid);
@@ -301,7 +355,7 @@ void main() {
}); });
test('getMessagesByCid along with pagination', () async { test('getMessagesByCid along with pagination', () async {
const cid = 'testCid'; const cid = 'test:Cid';
const limit = 15; const limit = 15;
const lessThan = 'testMessageId${cid}25'; const lessThan = 'testMessageId${cid}25';
const greaterThanOrEqual = 'testMessageId${cid}5'; const greaterThanOrEqual = 'testMessageId${cid}5';
@@ -333,7 +387,7 @@ void main() {
}); });
test('updateMessages', () async { test('updateMessages', () async {
const cid = 'testCid'; const cid = 'test:Cid';
// Preparing test data // Preparing test data
final insertedMessages = await _prepareTestData(cid); final insertedMessages = await _prepareTestData(cid);
@@ -23,6 +23,7 @@ void main() {
bool mapAllThreadToFirstMessage = false, bool mapAllThreadToFirstMessage = false,
int count = 3, int count = 3,
}) async { }) async {
final channels = [ChannelModel(cid: cid)];
final users = List.generate(count, (index) => User(id: 'testUserId$index')); final users = List.generate(count, (index) => User(id: 'testUserId$index'));
final messages = List.generate( final messages = List.generate(
count, count,
@@ -83,13 +84,20 @@ void main() {
if (quoted) ...quotedMessages, if (quoted) ...quotedMessages,
if (threads) ...threadMessages if (threads) ...threadMessages
]; ];
final reaction = Reaction(
type: 'type',
messageId: allMessages.first.id,
user: users.first,
);
await database.userDao.updateUsers(users); await database.userDao.updateUsers(users);
await database.channelDao.updateChannels(channels);
await pinnedMessageDao.updateMessages(cid, allMessages); await pinnedMessageDao.updateMessages(cid, allMessages);
await database.reactionDao.updateReactions([reaction]);
return allMessages; return allMessages;
} }
test('deleteMessageByIds', () async { test('deleteMessageByIds', () async {
const cid = 'testCid'; const cid = 'test:Cid';
// Preparing test data // Preparing test data
final insertedMessages = await _prepareTestData(cid); final insertedMessages = await _prepareTestData(cid);
@@ -98,66 +106,116 @@ void main() {
final messages = await pinnedMessageDao.getMessagesByCid(cid); final messages = await pinnedMessageDao.getMessagesByCid(cid);
expect(messages.length, insertedMessages.length); expect(messages.length, insertedMessages.length);
final firstMessageId = messages.first.id;
// Fetched reactions list should have one reaction for given message id
final reactions = await database.reactionDao.getReactions(firstMessageId);
expect(reactions.length, 1);
// Deleting 2 messages from DB // Deleting 2 messages from DB
await pinnedMessageDao.deleteMessageByIds( await pinnedMessageDao.deleteMessageByIds(
['testMessageId${cid}0', 'testMessageId${cid}1'], [firstMessageId, 'testMessageId${cid}1'],
); );
// New fetched messages length should 2 less than the // New fetched messages length should 2 less than the
// previous fetched messages // previous fetched messages
final newMessages = await pinnedMessageDao.getMessagesByCid(cid); final newMessages = await pinnedMessageDao.getMessagesByCid(cid);
expect(newMessages.length, messages.length - 2); expect(newMessages.length, messages.length - 2);
// Reaction for the first message should be deleted too
final newReactions =
await database.reactionDao.getReactions(firstMessageId);
expect(newReactions, isEmpty);
}); });
group('deleteMessageByCids', () { group('deleteMessageByCids', () {
const cid1 = 'testCid1'; const cid1 = 'test:Cid1';
const cid2 = 'testCid2'; const cid2 = 'test:Cid2';
test('should delete all the messages of first channel', () async { test(
// Preparing test data 'should delete all the messages and reactions of first channel',
final cid1InsertedMessages = await _prepareTestData(cid1); () async {
final cid2InsertedMessages = await _prepareTestData(cid2); // Preparing test data
final cid1InsertedMessages = await _prepareTestData(cid1);
final cid2InsertedMessages = await _prepareTestData(cid2);
// Fetched message list should match the test message list length // Fetched message list should match the test message list length
final cid1Messages = await pinnedMessageDao.getMessagesByCid(cid1); final cid1Messages = await pinnedMessageDao.getMessagesByCid(cid1);
final cid2Messages = await pinnedMessageDao.getMessagesByCid(cid2); final cid2Messages = await pinnedMessageDao.getMessagesByCid(cid2);
expect(cid1Messages.length, cid1InsertedMessages.length); expect(cid1Messages.length, cid1InsertedMessages.length);
expect(cid2Messages.length, cid2InsertedMessages.length); expect(cid2Messages.length, cid2InsertedMessages.length);
// Deleting all the messages of cid1 // Fetched reactions list should have one reaction for given message id
await pinnedMessageDao.deleteMessageByCids([cid1]); final cid1firstMessageId = cid1Messages.first.id;
final cid1Reactions =
await database.reactionDao.getReactions(cid1firstMessageId);
expect(cid1Reactions.length, 1);
// Fetched messages length of only cid1 should be empty // Deleting all the messages of cid1
final cid1FetchedMessages = await pinnedMessageDao.getMessagesByCid(cid1); await pinnedMessageDao.deleteMessageByCids([cid1]);
final cid2FetchedMessages = await pinnedMessageDao.getMessagesByCid(cid2);
expect(cid1FetchedMessages, isEmpty);
expect(cid2FetchedMessages, isNotEmpty);
});
test('should delete all the messages of both channel', () async { // Fetched messages length of only cid1 should be empty
// Preparing test data final cid1FetchedMessages =
final cid1InsertedMessages = await _prepareTestData(cid1); await pinnedMessageDao.getMessagesByCid(cid1);
final cid2InsertedMessages = await _prepareTestData(cid2); final cid2FetchedMessages =
await pinnedMessageDao.getMessagesByCid(cid2);
expect(cid1FetchedMessages, isEmpty);
expect(cid2FetchedMessages, isNotEmpty);
// Fetched message list should match the test message list length // Reaction for the first message should be deleted too
final cid1Messages = await pinnedMessageDao.getMessagesByCid(cid1); final cid1FetchedReactions =
final cid2Messages = await pinnedMessageDao.getMessagesByCid(cid2); await database.reactionDao.getReactions(cid1firstMessageId);
expect(cid1Messages.length, cid1InsertedMessages.length); expect(cid1FetchedReactions, isEmpty);
expect(cid2Messages.length, cid2InsertedMessages.length); },
);
// Deleting all the messages of cid1 test(
await pinnedMessageDao.deleteMessageByCids([cid1, cid2]); 'should delete all the messages and reactions of both channel',
() async {
// Preparing test data
final cid1InsertedMessages = await _prepareTestData(cid1);
final cid2InsertedMessages = await _prepareTestData(cid2);
// Fetched messages length of both cid1 and cid2 should be empty // Fetched message list should match the test message list length
final cid1FetchedMessages = await pinnedMessageDao.getMessagesByCid(cid1); final cid1Messages = await pinnedMessageDao.getMessagesByCid(cid1);
final cid2FetchedMessages = await pinnedMessageDao.getMessagesByCid(cid2); final cid2Messages = await pinnedMessageDao.getMessagesByCid(cid2);
expect(cid1FetchedMessages, isEmpty); expect(cid1Messages.length, cid1InsertedMessages.length);
expect(cid2FetchedMessages, isEmpty); expect(cid2Messages.length, cid2InsertedMessages.length);
});
// Fetched reactions list should have one reaction for given message id
final cid1FirstMessageId = cid1Messages.first.id;
final cid1Reactions =
await database.reactionDao.getReactions(cid1FirstMessageId);
expect(cid1Reactions.length, 1);
final cid2FirstMessageId = cid2Messages.first.id;
final cid2Reactions =
await database.reactionDao.getReactions(cid2FirstMessageId);
expect(cid2Reactions.length, 1);
// Deleting all the messages of cid1
await pinnedMessageDao.deleteMessageByCids([cid1, cid2]);
// Fetched messages length of both cid1 and cid2 should be empty
final cid1FetchedMessages =
await pinnedMessageDao.getMessagesByCid(cid1);
final cid2FetchedMessages =
await pinnedMessageDao.getMessagesByCid(cid2);
expect(cid1FetchedMessages, isEmpty);
expect(cid2FetchedMessages, isEmpty);
// Reaction for the first message should be deleted too
final cid1FetchedReactions =
await database.reactionDao.getReactions(cid1FirstMessageId);
expect(cid1FetchedReactions, isEmpty);
final cid2FetchedReactions =
await database.reactionDao.getReactions(cid2FirstMessageId);
expect(cid2FetchedReactions, isEmpty);
},
);
}); });
test('getMessageById', () async { test('getMessageById', () async {
const cid = 'testCid'; const cid = 'test:Cid';
const id = 'testMessageId${cid}0'; const id = 'testMessageId${cid}0';
// Should be null initially // Should be null initially
@@ -175,7 +233,7 @@ void main() {
}); });
test('getThreadMessages', () async { test('getThreadMessages', () async {
const cid = 'testCid'; const cid = 'test:Cid';
// Messages should be empty initially // Messages should be empty initially
final messages = await pinnedMessageDao.getThreadMessages(cid); final messages = await pinnedMessageDao.getThreadMessages(cid);
@@ -194,7 +252,7 @@ void main() {
}); });
test('getThreadMessagesByParentId', () async { test('getThreadMessagesByParentId', () async {
const cid = 'testCid'; const cid = 'test:Cid';
const parentId = 'testMessageId${cid}0'; const parentId = 'testMessageId${cid}0';
// Messages should be empty initially // Messages should be empty initially
@@ -214,7 +272,7 @@ void main() {
}); });
test('getThreadMessagesByParentId along with pagination', () async { test('getThreadMessagesByParentId along with pagination', () async {
const cid = 'testCid'; const cid = 'test:Cid';
const parentId = 'testMessageId${cid}0'; const parentId = 'testMessageId${cid}0';
const options = PaginationParams( const options = PaginationParams(
limit: 15, limit: 15,
@@ -248,7 +306,7 @@ void main() {
}); });
test('getMessagesByCid', () async { test('getMessagesByCid', () async {
const cid = 'testCid'; const cid = 'test:Cid';
// Should be empty initially // Should be empty initially
final messages = await pinnedMessageDao.getMessagesByCid(cid); final messages = await pinnedMessageDao.getMessagesByCid(cid);
@@ -269,7 +327,7 @@ void main() {
}); });
test('getMessagesByCid along with quotedMessage', () async { test('getMessagesByCid along with quotedMessage', () async {
const cid = 'testCid'; const cid = 'test:Cid';
// Should be empty initially // Should be empty initially
final messages = await pinnedMessageDao.getMessagesByCid(cid); final messages = await pinnedMessageDao.getMessagesByCid(cid);
@@ -287,7 +345,7 @@ void main() {
}); });
test('getMessagesByCid along with pagination', () async { test('getMessagesByCid along with pagination', () async {
const cid = 'testCid'; const cid = 'test:Cid';
const limit = 15; const limit = 15;
const lessThan = 'testMessageId${cid}25'; const lessThan = 'testMessageId${cid}25';
const greaterThanOrEqual = 'testMessageId${cid}5'; const greaterThanOrEqual = 'testMessageId${cid}5';
@@ -319,7 +377,7 @@ void main() {
}); });
test('updateMessages', () async { test('updateMessages', () async {
const cid = 'testCid'; const cid = 'test:Cid';
// Preparing test data // Preparing test data
final insertedMessages = await _prepareTestData(cid); final insertedMessages = await _prepareTestData(cid);
@@ -21,6 +21,8 @@ void main() {
String? userId, String? userId,
int count = 3, int count = 3,
}) async { }) async {
const cid = 'test:Cid';
final channels = [ChannelModel(cid: cid)];
final users = List.generate(count, (index) => User(id: 'testUserId$index')); final users = List.generate(count, (index) => User(id: 'testUserId$index'));
final message = Message( final message = Message(
id: messageId, id: messageId,
@@ -50,7 +52,8 @@ void main() {
); );
await database.userDao.updateUsers(users); await database.userDao.updateUsers(users);
await database.messageDao.updateMessages('testCid', [message]); await database.channelDao.updateChannels(channels);
await database.messageDao.updateMessages(cid, [message]);
await reactionDao.updateReactions(reactions); await reactionDao.updateReactions(reactions);
return reactions; return reactions;
@@ -16,6 +16,7 @@ void main() {
}); });
Future<List<Read>> _prepareReadData(String cid, {int count = 3}) async { Future<List<Read>> _prepareReadData(String cid, {int count = 3}) async {
final channels = [ChannelModel(cid: cid)];
final users = List.generate(count, (index) => User(id: 'testUserId$index')); final users = List.generate(count, (index) => User(id: 'testUserId$index'));
final reads = List.generate( final reads = List.generate(
count, count,
@@ -27,12 +28,13 @@ void main() {
); );
await database.userDao.updateUsers(users); await database.userDao.updateUsers(users);
await database.channelDao.updateChannels(channels);
await readDao.updateReads(cid, reads); await readDao.updateReads(cid, reads);
return reads; return reads;
} }
test('getReadsByCid', () async { test('getReadsByCid', () async {
const cid = 'testCid'; const cid = 'test:Cid';
// Should be empty initially // Should be empty initially
final reads = await readDao.getReadsByCid(cid); final reads = await readDao.getReadsByCid(cid);
@@ -55,7 +57,7 @@ void main() {
}); });
test('updateReads', () async { test('updateReads', () async {
const cid = 'testCid'; const cid = 'test:Cid';
// Preparing test data // Preparing test data
final insertedReads = await _prepareReadData(cid); final insertedReads = await _prepareReadData(cid);