From 8faf5643a534a589918ebec9db4dd33e141a23d0 Mon Sep 17 00:00:00 2001 From: Lucas Pelegrino Date: Wed, 10 Dec 2025 17:07:45 -0300 Subject: [PATCH 1/2] chore: replaces legacy livechat:saveCustomFields with new endpoint on test helpers --- .../tests/data/livechat/custom-fields.ts | 71 ++++++------------- 1 file changed, 22 insertions(+), 49 deletions(-) diff --git a/apps/meteor/tests/data/livechat/custom-fields.ts b/apps/meteor/tests/data/livechat/custom-fields.ts index dc063b100e374..e73d1c441fe2b 100644 --- a/apps/meteor/tests/data/livechat/custom-fields.ts +++ b/apps/meteor/tests/data/livechat/custom-fields.ts @@ -1,56 +1,29 @@ import type { ILivechatCustomField } from '@rocket.chat/core-typings'; -import type { Response } from 'supertest'; -import { credentials, request, methodCall, api } from '../api-data'; +import { credentials, request, api } from '../api-data'; type ExtendedCustomField = Omit & { field: string }; -export const createCustomField = (customField: ExtendedCustomField): Promise => - new Promise((resolve, reject) => { - void 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 { - void 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 createCustomField = async (customFieldData: ExtendedCustomField): Promise => { + const response = await request + .get(api(`livechat/custom-fields/${customFieldData.label}`)) + .set(credentials) + .send(); + + if (response.body.customField) { + return response.body.customField; + } + + const { body } = await request.post(api('livechat/custom-fields.save')).set(credentials).send({ customFieldData }); -export const deleteCustomField = (customFieldID: string) => - new Promise((resolve, reject) => { - void request - .post(api('livechat/custom-fields.delete')) - .set(credentials) - .send({ - customFieldId: customFieldID, - }) - .end((err: Error, res: Response): void => { - if (err) { - return reject(err); - } - resolve(res.body); - }); + return body.customField; +}; + +export const deleteCustomField = async (customFieldId: string) => { + console.log(`Deleting custom field with id: ${customFieldId}`); + const { body } = await request.post(api('livechat/custom-fields.delete')).set(credentials).send({ + customFieldId, }); + + return body; +}; From 7faafdf9aa5929a464afce44a5f6e1842a28c621 Mon Sep 17 00:00:00 2001 From: Lucas Pelegrino Date: Wed, 10 Dec 2025 18:05:08 -0300 Subject: [PATCH 2/2] chore: keeps promise syntax while updating it to use the new endpoint --- .../tests/data/livechat/custom-fields.ts | 62 ++++++++++++------- 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/apps/meteor/tests/data/livechat/custom-fields.ts b/apps/meteor/tests/data/livechat/custom-fields.ts index e73d1c441fe2b..b1f4244e3ab82 100644 --- a/apps/meteor/tests/data/livechat/custom-fields.ts +++ b/apps/meteor/tests/data/livechat/custom-fields.ts @@ -1,29 +1,49 @@ import type { ILivechatCustomField } from '@rocket.chat/core-typings'; +import type { Response } from 'supertest'; import { credentials, request, api } from '../api-data'; type ExtendedCustomField = Omit & { field: string }; -export const createCustomField = async (customFieldData: ExtendedCustomField): Promise => { - const response = await request - .get(api(`livechat/custom-fields/${customFieldData.label}`)) - .set(credentials) - .send(); - - if (response.body.customField) { - return response.body.customField; - } - - const { body } = await request.post(api('livechat/custom-fields.save')).set(credentials).send({ customFieldData }); - - return body.customField; -}; - -export const deleteCustomField = async (customFieldId: string) => { - console.log(`Deleting custom field with id: ${customFieldId}`); - const { body } = await request.post(api('livechat/custom-fields.delete')).set(credentials).send({ - customFieldId, +export const createCustomField = (customField: ExtendedCustomField): Promise => + new Promise((resolve, reject) => { + void 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 { + void request + .post(api('livechat/custom-fields.save')) + .set(credentials) + .send({ customFieldId: null, customFieldData: customField }) + .end((err: Error, res: Response): void => { + if (err) { + return reject(err); + } + resolve(res.body.customField); + }); + } + }); }); - return body; -}; +export const deleteCustomField = (customFieldID: string) => + new Promise((resolve, reject) => { + void request + .post(api('livechat/custom-fields.delete')) + .set(credentials) + .send({ + customFieldId: customFieldID, + }) + .end((err: Error, res: Response): void => { + if (err) { + return reject(err); + } + resolve(res.body); + }); + });