diff --git a/.changeset/three-insects-roll.md b/.changeset/three-insects-roll.md new file mode 100644 index 000000000000..ae4f206dd83e --- /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 eb1d190977b3..ab40e42aaf82 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 7953e772c016..4ebd4ccc2aee 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();