From bb5b08d29cb40e9456f721128fd27f272b542a70 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Fri, 24 Jan 2025 14:34:27 -0300 Subject: [PATCH] fix: tag endpoint empty result (#35028) Co-authored-by: Kevin Aleman --- .changeset/three-insects-roll.md | 5 +++++ .../app/livechat-enterprise/server/api/tags.ts | 16 ++++++++++------ .../tests/end-to-end/api/livechat/13-tags.ts | 3 +-- 3 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 .changeset/three-insects-roll.md diff --git a/.changeset/three-insects-roll.md b/.changeset/three-insects-roll.md new file mode 100644 index 0000000000000..ae4f206dd83ef --- /dev/null +++ b/.changeset/three-insects-roll.md @@ -0,0 +1,5 @@ +--- +"@rocket.chat/meteor": patch +--- + +Fixes a missconception about `/v1/livechat/tags/:tagId` returning 404 if tag is not found diff --git a/apps/meteor/ee/app/livechat-enterprise/server/api/tags.ts b/apps/meteor/ee/app/livechat-enterprise/server/api/tags.ts index eb1d190977b3f..ab40e42aaf82f 100644 --- a/apps/meteor/ee/app/livechat-enterprise/server/api/tags.ts +++ b/apps/meteor/ee/app/livechat-enterprise/server/api/tags.ts @@ -35,12 +35,16 @@ API.v1.addRoute( async get() { const { tagId } = this.urlParams; - return API.v1.success( - await findTagById({ - userId: this.userId, - tagId, - }), - ); + const tag = await findTagById({ + userId: this.userId, + tagId, + }); + + if (!tag) { + return API.v1.notFound('Tag not found'); + } + + return API.v1.success(tag); }, }, ); diff --git a/apps/meteor/tests/end-to-end/api/livechat/13-tags.ts b/apps/meteor/tests/end-to-end/api/livechat/13-tags.ts index 7953e772c016f..4ebd4ccc2aee6 100644 --- a/apps/meteor/tests/end-to-end/api/livechat/13-tags.ts +++ b/apps/meteor/tests/end-to-end/api/livechat/13-tags.ts @@ -235,8 +235,7 @@ import { IS_EE } from '../../../e2e/config/constants'; it('should return null when the tag does not exist', async () => { await updatePermission('manage-livechat-tags', ['admin']); await updatePermission('view-l-room', ['livechat-agent']); - const response = await request.get(api('livechat/tags/123')).set(credentials).expect('Content-Type', 'application/json').expect(200); - expect(response.body.body).to.be.null; + await request.get(api('livechat/tags/123')).set(credentials).expect('Content-Type', 'application/json').expect(404); }); it('should return a tag', async () => { const tag = await saveTags();