Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions plugin-hrm-form/src/___tests__/maskIdentifiers/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ describe('maskConversationServiceUserNames', () => {
strings: {
MaskIdentifiers: 'MASKED',
},
user: {
identity: 'current-user-identity',
},
store: {
subscribe: jest.fn((callback: () => void) => {
storeSubscribeCallback = callback;
Expand All @@ -56,10 +59,11 @@ describe('maskConversationServiceUserNames', () => {
jest.clearAllMocks();
});

const createParticipant = (sid: string, attributes: Record<string, any> = {}) => ({
const createParticipant = (sid: string, attributes: Record<string, any> = {}, identity?: string) => ({
source: {
sid,
attributes,
...(identity && { identity }),
},
friendlyName: 'Original Name',
});
Expand All @@ -78,6 +82,27 @@ describe('maskConversationServiceUserNames', () => {
});

each([
{
testCase: 'identity matches manager user identity, regardless of other checks',
participantAttributes: {},
participantIdentity: 'current-user-identity',
flexParticipants: {},
expectedName: 'Original Name',
},
{
testCase: 'identity matches manager user identity, even with guest member_type',
participantAttributes: { member_type: 'guest' },
participantIdentity: 'current-user-identity',
flexParticipants: {},
expectedName: 'Original Name',
},
{
testCase: 'identity matches manager user identity, even when not in flex store',
participantAttributes: {},
participantIdentity: 'current-user-identity',
flexParticipants: { participant1: { type: 'customer', sid: 'MB999' } },
expectedName: 'Original Name',
},
Comment on lines 84 to +105
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a test case where manager.user.identity is undefined or null to ensure the new identity check handles this edge case correctly. This would verify that participants aren't incorrectly identified as agents when both identities are missing.

Copilot uses AI. Check for mistakes.
{
testCase: 'no member_type attribute and not in flex store as agent',
participantAttributes: {},
Expand Down Expand Up @@ -122,10 +147,10 @@ describe('maskConversationServiceUserNames', () => {
},
]).test(
'participant should have correct masking when $testCase',
({ participantAttributes, flexParticipants, expectedName }) => {
({ participantAttributes, participantIdentity, flexParticipants, expectedName }) => {
const conversationSid = 'CH123';
const participantSid = 'MB456';
const participant = createParticipant(participantSid, participantAttributes);
const participant = createParticipant(participantSid, participantAttributes, participantIdentity);

const bySid: Record<string, ReturnType<typeof createFlexParticipant>> = {};
Object.entries(flexParticipants).forEach(([key, value]) => {
Expand Down
5 changes: 4 additions & 1 deletion plugin-hrm-form/src/maskIdentifiers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ export const maskConversationServiceUserNames = (manager: Manager) => {
for (const [conversationSid, conversation] of Object.entries(chat.conversations)) {
for (const participant of conversation.participants.values()) {
let isAgent: boolean;
if (participant.source.attributes['member_type']) {
if (participant.source.identity && participant.source.identity === manager.user.identity) {
// Identity matches logged in user's identity, it's the current user
isAgent = true;
} else if (participant.source.attributes['member_type']) {
// Webchat 2 over programmable chat, check if participant is a guest
// Programmable Chat conversation participants are not listed in the 'participants' redux store, so checking that store does not work for them
// However they do have a member_type attribute set on the participant in the conversation, so we can use that
Expand Down
Loading