Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/api/lib/livechat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export async function settings({ businessUnit = '' }: { businessUnit?: string }
};
}

export async function getExtraConfigInfo(room: IOmnichannelRoom): Promise<any> {
export async function getExtraConfigInfo(room?: IOmnichannelRoom): Promise<any> {
return callbacks.run('livechat.onLoadConfigApi', { room });
}

Expand Down
7 changes: 4 additions & 3 deletions apps/meteor/app/livechat/server/api/v1/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import mem from 'mem';
import { isGETLivechatConfigParams } from '@rocket.chat/rest-typings';
import type { ILivechatVisitor, IOmnichannelRoom } from '@rocket.chat/core-typings';

import { API } from '../../../../api/server';
import { Livechat } from '../../lib/Livechat';
Expand All @@ -23,12 +24,12 @@ API.v1.addRoute(
const config = await cachedSettings({ businessUnit });

const status = Livechat.online(department);
const guest = token && (await Livechat.findGuest(token));
const guest: ILivechatVisitor | null = token ? await Livechat.findGuest(token) : null;
Comment thread
murtaza98 marked this conversation as resolved.
Outdated
Comment thread
KevLehman marked this conversation as resolved.
Outdated

const room = guest && findOpenRoom(token);
const room: IOmnichannelRoom | undefined = guest ? findOpenRoom(guest.token) : undefined;
Comment thread
KevLehman marked this conversation as resolved.
Outdated
const agent = guest && room && room.servedBy && findAgent(room.servedBy._id);

const extra = room && (await getExtraConfigInfo(room));
const extra = await getExtraConfigInfo(room);
return API.v1.success({
config: { ...config, online: status, ...extra, ...(guest && { guest }), ...(room && { room }), ...(agent && { agent }) },
});
Expand Down
11 changes: 9 additions & 2 deletions apps/meteor/tests/data/livechat/custom-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@ export const createCustomField = (customField: ILivechatCustomField) => new Prom

export const deleteCustomField = (customFieldID: string) => new Promise((resolve, reject) => {
request
.post(methodCall('livechat:saveCustomField'))
.send(customFieldID)
.post(methodCall('livechat:removeCustomField'))
.send({
message: JSON.stringify({
method: 'livechat:removeCustomField',
params: [customFieldID],
id: 'id',
msg: 'method',
}),
})
.set(credentials)
.end((err: Error, res: Response): void => {
if (err) {
Expand Down
29 changes: 29 additions & 0 deletions apps/meteor/tests/end-to-end/api/livechat/11-livechat.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* eslint-env mocha */

import type { ILivechatCustomField } from '@rocket.chat/core-typings';
import { expect } from 'chai';

import { getCredentials, api, request, credentials } from '../../../data/api-data';
import { createCustomField, deleteCustomField } from '../../../data/livechat/custom-fields';
import { createVisitor, createLivechatRoom } from '../../../data/livechat/rooms';
import { updateSetting } from '../../../data/permissions.helper';

Expand Down Expand Up @@ -75,6 +77,33 @@ describe('LIVECHAT - Utils', function () {
expect(body.config).to.have.property('settings');
expect(body.config).to.have.property('departments').that.is.an('array');
});
it('should have custom fields data', async () => {
const customFieldName = `new_custom_field_${Date.now()}`;
await createCustomField({
searchable: true,
field: customFieldName,
label: customFieldName,
defaultValue: 'test_default_address',
scope: 'visitor',
visibility: 'visible',
regexp: '',
public: true,
required: false,

options: '',
} as unknown as ILivechatCustomField & { field: string });
Comment thread
KevLehman marked this conversation as resolved.
Outdated

const { body } = await request.get(api('livechat/config')).set(credentials);

expect(body).to.have.property('config');
expect(body.config).to.have.property('customFields').that.is.an('array');
expect(body.config.customFields).to.have.length.greaterThan(0);
const customField = body.config.customFields.find((field: any) => field._id === customFieldName);
expect(customField).to.be.an('object');
expect(customField).to.have.property('label', customFieldName);

await deleteCustomField(customFieldName);
});
});

describe('livechat/page.visited', () => {
Expand Down