Skip to content

Commit

Permalink
regression: lastChat property missing on contact migrated from visi…
Browse files Browse the repository at this point in the history
…tor (#34016)
  • Loading branch information
matheusbsilva137 authored Nov 21, 2024
1 parent 5b01136 commit 31362ac
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ILivechatContactChannel } from '@rocket.chat/core-typings';
import type { ILivechatContactChannel, IVisitorLastChat } from '@rocket.chat/core-typings';
import { LivechatContacts } from '@rocket.chat/models';

import { getAllowedCustomFields } from './getAllowedCustomFields';
Expand All @@ -11,6 +11,7 @@ export type CreateContactParams = {
phones?: string[];
unknown: boolean;
customFields?: Record<string, string | unknown>;
lastChat?: IVisitorLastChat;
contactManager?: string;
channels?: ILivechatContactChannel[];
importIds?: string[];
Expand All @@ -21,6 +22,7 @@ export async function createContact({
emails,
phones,
customFields: receivedCustomFields = {},
lastChat,
contactManager,
channels = [],
unknown,
Expand All @@ -40,6 +42,7 @@ export async function createContact({
contactManager,
channels,
customFields,
lastChat,
unknown,
...(importIds?.length && { importIds }),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const { mapVisitorToContact } = proxyquire.noCallThru().load('./mapVisitorToCont
},
});

const testDate = new Date();
const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactParams][] = [
[
{
Expand Down Expand Up @@ -87,6 +88,48 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
contactManager: undefined,
},
],

[
{
_id: 'visitor1',
username: 'Username',
lastChat: {
_id: 'last-chat-id',
ts: testDate,
},
},
{
type: OmnichannelSourceType.WIDGET,
},
{
name: 'Username',
emails: undefined,
phones: undefined,
unknown: false,
channels: [
{
name: 'sms',
visitor: {
visitorId: 'visitor1',
source: {
type: OmnichannelSourceType.WIDGET,
},
},
blocked: false,
verified: false,
details: {
type: OmnichannelSourceType.WIDGET,
},
},
],
customFields: undefined,
lastChat: {
_id: 'last-chat-id',
ts: testDate,
},
contactManager: undefined,
},
],
];

describe('mapVisitorToContact', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export async function mapVisitorToContact(visitor: ILivechatVisitor, source: IOm
},
],
customFields: visitor.livechatData,
lastChat: visitor.lastChat,
contactManager: visitor.contactManager?.username && (await getContactManagerIdByUsername(visitor.contactManager.username)),
};
}

0 comments on commit 31362ac

Please sign in to comment.