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
5 changes: 5 additions & 0 deletions .changeset/warm-steaks-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixes contact's conflict resolution not working due to invalid parameters
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const ReviewContactModal = ({ contact, onCancel }: ReviewContactModalProps) => {
const payload = {
name,
contactManager,
...(customFields && { ...customFields }),
...(customFields && { customFields }),
wipeConflicts: true,
};

Expand Down Expand Up @@ -86,24 +86,32 @@ const ReviewContactModal = ({ contact, onCancel }: ReviewContactModalProps) => {

return (
<Field key={index}>
<FieldLabel>{t(label as TranslationKey)}</FieldLabel>
<FieldLabel id={name}>{t(label as TranslationKey)}</FieldLabel>
<FieldRow>
<Controller
name={name}
control={control}
rules={{
required: isContactManagerField ? undefined : t('Required_field', { field: t(label as TranslationKey) }),
}}
render={({ field: { value, onChange } }) => <Component options={mappedOptions} value={value} onChange={onChange} />}
render={({ field: { value, onChange } }) => (
<Component
aria-labelledby={name}
aria-describedby={`${name}-hint ${name}-error`}
options={mappedOptions}
value={value}
onChange={onChange}
/>
)}
/>
</FieldRow>
<FieldHint>
<FieldHint id={`${name}-hint`}>
<Box display='flex' alignItems='center'>
<Box mie={4}>{t('different_values_found', { number: values.length })}</Box>
<Badge variant='primary' small />
</Box>
</FieldHint>
{errors?.[name] && <FieldError>{errors?.[name]?.message}</FieldError>}
{errors?.[name] && <FieldError id={`${name}-error`}>{errors?.[name]?.message}</FieldError>}
</Field>
);
})}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { faker } from '@faker-js/faker';

import { createFakeVisitor } from '../../mocks/data';
import { IS_EE } from '../config/constants';
import { Users } from '../fixtures/userStates';
import { HomeOmnichannel } from '../page-objects';
import { createCustomField } from '../utils/omnichannel/custom-field';
import { createConversation } from '../utils/omnichannel/rooms';
import { test, expect } from '../utils/test';

const visitor = createFakeVisitor();

test.skip(!IS_EE, 'Omnichannel Contact Review > Enterprise Only');

test.use({ storageState: Users.user1.state });

test.describe.serial('OC - Contact Review', () => {
let poHomeChannel: HomeOmnichannel;

const customFieldName = faker.string.uuid();
const visitorToken = faker.string.uuid();
let conversation: Awaited<ReturnType<typeof createConversation>>;
let customField: Awaited<ReturnType<typeof createCustomField>>;

test.beforeAll(async ({ api }) => {
(
await Promise.all([
api.post('/livechat/users/agent', { username: 'user1' }),
api.post('/livechat/users/manager', { username: 'user1' }),
])
).every((res) => expect(res.status()).toBe(200));

customField = await createCustomField(api, { field: customFieldName });
});

test.beforeEach(async ({ page }) => {
poHomeChannel = new HomeOmnichannel(page);
});

test.beforeEach(async ({ page }) => {
await page.goto('/');
await page.locator('.main-content').waitFor();
});

test.beforeEach(async ({ api }) => {
conversation = await createConversation(api, { visitorName: visitor.name, agentId: `user1`, visitorToken });
});

test.beforeEach(async ({ api }) => {
const resCustomFieldA = await api.post('/livechat/custom.field', {
token: visitorToken,
key: customFieldName,
value: 'custom-field-value',
overwrite: true,
});

expect(resCustomFieldA.status()).toBe(200);

const resCustomFieldB = await api.post('/livechat/custom.field', {
token: visitorToken,
key: customFieldName,
value: 'custom-field-value-2',
overwrite: false,
});

expect(resCustomFieldB.status()).toBe(200);
});

test.afterAll(async ({ api }) => {
(await Promise.all([api.delete('/livechat/users/agent/user1'), api.delete('/livechat/users/manager/user1')])).every((res) =>
expect(res.status()).toBe(200),
);

await conversation.delete();
await customField.delete();
});

test('OC - Contact Review - Update custom field conflicting', async ({ page }) => {
await poHomeChannel.sidenav.getSidebarItemByName(visitor.name).click();
await poHomeChannel.content.btnContactInformation.click();

await poHomeChannel.content.contactReviewModal.btnSeeConflicts.click();

await poHomeChannel.content.contactReviewModal.getFieldByName(customFieldName).click();
await poHomeChannel.content.contactReviewModal.findOption('custom-field-value-2').click();
await poHomeChannel.content.contactReviewModal.btnSave.click();

const response = await page.waitForResponse('**/api/v1/omnichannel/contacts.update');
await expect(response.status()).toBe(200);

await expect(poHomeChannel.content.contactReviewModal.btnSeeConflicts).not.toBeVisible();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ import type { Locator, Page } from '@playwright/test';
import { OmnichannelTransferChatModal } from '../omnichannel-transfer-chat-modal';
import { HomeContent } from './home-content';
import { OmnichannelCloseChatModal } from './omnichannel-close-chat-modal';
import { OmnichannelContactReviewModal } from '../omnichannel-contact-review-modal';

export class HomeOmnichannelContent extends HomeContent {
readonly closeChatModal: OmnichannelCloseChatModal;

readonly forwardChatModal: OmnichannelTransferChatModal;

readonly contactReviewModal: OmnichannelContactReviewModal;

constructor(page: Page) {
super(page);
this.closeChatModal = new OmnichannelCloseChatModal(page);
this.forwardChatModal = new OmnichannelTransferChatModal(page);
this.contactReviewModal = new OmnichannelContactReviewModal(page);
}

get btnReturnToQueue(): Locator {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { Locator, Page } from '@playwright/test';

export class OmnichannelContactReviewModal {
private readonly page: Page;

constructor(page: Page) {
this.page = page;
}

get btnSeeConflicts(): Locator {
return this.page.getByRole('button', { name: 'See conflicts', exact: true });
}

get btnSave(): Locator {
return this.page.getByRole('button', { name: 'Save', exact: true });
}

getFieldByName(name: string): Locator {
return this.page.getByLabel(name, { exact: true });
}

findOption(name: string): Locator {
return this.page.getByRole('option', { name, exact: true });
}
}
54 changes: 54 additions & 0 deletions apps/meteor/tests/e2e/utils/omnichannel/custom-field.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import type { ILivechatCustomField } from '@rocket.chat/core-typings';

import { parseMeteorResponse } from '../parseMeteorResponse';
import type { BaseTest } from '../test';

type CustomField = Omit<ILivechatCustomField, '_id' | '_updatedAt'> & { field: string };

export const removeCustomField = (api: BaseTest['api'], id: string) => {
return api.post('/method.call/livechat:deleteCustomField', {
method: 'livechat:saveCustomField',
params: [id],
id: 'id',
msg: 'method',
});
};

export const createCustomField = async (api: BaseTest['api'], overwrides: Partial<CustomField>) => {
const response = await api.post('/method.call/livechat:saveCustomField', {
message: JSON.stringify({
method: 'livechat:saveCustomField',
params: [
null,
{
field: overwrides.field,
label: overwrides.label || overwrides.field,
visibility: 'visible',
scope: 'visitor',
searchable: false,
regexp: '',
type: 'input',
required: false,
defaultValue: '',
options: '',
public: false,
...overwrides,
},
],
id: 'id',
msg: 'method',
}),
});

if (!response.ok()) {
throw new Error(`Failed to create custom field [http status: ${response.status()}]`);
}

const customField = await parseMeteorResponse<CustomField & { _id: string }>(response);

return {
response,
customField,
delete: () => removeCustomField(api, customField._id),
};
};
Loading