Fix private calls
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import {
|
||||
advanceDirectMessageStatus,
|
||||
createDirectConversation,
|
||||
createGroupConversation,
|
||||
getDirectConversationId,
|
||||
isGroupDirectConversation,
|
||||
updateMessageStatusInConversation,
|
||||
upsertDirectMessage
|
||||
} from '../../domain/logic/direct-message.logic';
|
||||
@@ -17,6 +19,11 @@ const bob: DirectMessageParticipant = {
|
||||
username: 'bob',
|
||||
displayName: 'Bob'
|
||||
};
|
||||
const charlie: DirectMessageParticipant = {
|
||||
userId: 'charlie',
|
||||
username: 'charlie',
|
||||
displayName: 'Charlie'
|
||||
};
|
||||
|
||||
describe('DirectMessageService domain flow', () => {
|
||||
it('should create conversation', () => {
|
||||
@@ -44,6 +51,41 @@ describe('DirectMessageService domain flow', () => {
|
||||
expect(updatedConversation.messages[0].status).toBe('QUEUED');
|
||||
});
|
||||
|
||||
it('should create empty group conversation without direct-message history', () => {
|
||||
const directConversation = upsertDirectMessage(createDirectConversation(alice, bob, 10), createMessage('message-1', 'SENT'), false);
|
||||
const groupConversation = createGroupConversation('dm-group-test', [
|
||||
alice,
|
||||
bob,
|
||||
charlie
|
||||
], 30, 'Alice, Bob, Charlie');
|
||||
|
||||
expect(isGroupDirectConversation(groupConversation)).toBe(true);
|
||||
expect(groupConversation.id).toBe('dm-group-test');
|
||||
expect(groupConversation.title).toBe('Alice, Bob, Charlie');
|
||||
expect(groupConversation.participants).toEqual([
|
||||
'alice',
|
||||
'bob',
|
||||
'charlie'
|
||||
]);
|
||||
|
||||
expect(groupConversation.messages).toEqual([]);
|
||||
expect(directConversation.messages).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('should preserve group message recipient metadata', () => {
|
||||
const conversation = createGroupConversation('dm-group-test', [
|
||||
alice,
|
||||
bob,
|
||||
charlie
|
||||
], 10);
|
||||
const recipientIds = ['bob', 'charlie'];
|
||||
const message = createMessage('message-1', 'QUEUED', conversation.id, recipientIds);
|
||||
const updatedConversation = upsertDirectMessage(conversation, message, false);
|
||||
|
||||
expect(updatedConversation.messages[0].recipientId).toBe('bob');
|
||||
expect(updatedConversation.messages[0].recipientIds).toEqual(recipientIds);
|
||||
});
|
||||
|
||||
it('should update status correctly', () => {
|
||||
expect(advanceDirectMessageStatus('QUEUED', 'SENT')).toBe('SENT');
|
||||
expect(advanceDirectMessageStatus('SENT', 'DELIVERED')).toBe('DELIVERED');
|
||||
@@ -52,12 +94,18 @@ describe('DirectMessageService domain flow', () => {
|
||||
});
|
||||
});
|
||||
|
||||
function createMessage(id: string, status: DirectMessage['status']): DirectMessage {
|
||||
function createMessage(
|
||||
id: string,
|
||||
status: DirectMessage['status'],
|
||||
conversationId = getDirectConversationId('alice', 'bob'),
|
||||
recipientIds = ['bob']
|
||||
): DirectMessage {
|
||||
return {
|
||||
id,
|
||||
conversationId: getDirectConversationId('alice', 'bob'),
|
||||
conversationId,
|
||||
senderId: 'alice',
|
||||
recipientId: 'bob',
|
||||
recipientId: recipientIds[0],
|
||||
recipientIds,
|
||||
content: 'Hello',
|
||||
timestamp: 20,
|
||||
status
|
||||
|
||||
Reference in New Issue
Block a user