The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Rocket.Chat/apps/meteor/tests/data/livechat/custom-fields.ts

61 lines
2.0 KiB

import type { Response } from 'supertest';
import type { ILivechatCustomField } from '@rocket.chat/core-typings';
import { credentials, request, methodCall, api } from './../api-data';
type ExtendedCustomField = Omit<ILivechatCustomField, '_id' | '_updatedAt'> & { field: string };
export const createCustomField = (customField: ExtendedCustomField): Promise<ExtendedCustomField> => new Promise((resolve, reject) => {
request
.get(api(`livechat/custom-fields/${customField.label}`))
.set(credentials)
.send()
.end((err: Error, res: Response) => {
if (err) {
return reject(err);
}
if (res.body.customField != null && res.body.customField != undefined) {
resolve(res.body.customField);
} else {
request
.post(methodCall('livechat:saveCustomField'))
.send({
message: JSON.stringify({
method: 'livechat:saveCustomField',
params: [null, customField],
id: 'id',
msg: 'method',
}),
})
.set(credentials)
.end((err: Error, res: Response): void => {
if (err) {
return reject(err);
}
resolve(res.body);
});
}
});
});
export const deleteCustomField = (customFieldID: string) => new Promise((resolve, reject) => {
request
.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) {
return reject(err);
}
resolve(res.body);
});
});