From 64f1a809639062a0b16520044414638fa6958385 Mon Sep 17 00:00:00 2001 From: Lucas Mendes <92529166+lucasmendes21@users.noreply.github.com> Date: Fri, 24 Jan 2025 14:45:41 -0300 Subject: [PATCH] [UXE-6102] fix: improve status parsing and handle optional results in list data stream (#2091) --- .../list-data-stream-service.js | 27 ++++++++++--------- .../list-data-stream-service.test.js | 17 ++++++++++++ 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/services/data-stream-services/list-data-stream-service.js b/src/services/data-stream-services/list-data-stream-service.js index 6a7be0c30..843a7ccfa 100644 --- a/src/services/data-stream-services/list-data-stream-service.js +++ b/src/services/data-stream-services/list-data-stream-service.js @@ -46,13 +46,13 @@ const adaptTemplate = (httpResponse) => { const parseStatusData = (status) => { const parsedStatus = status ? { - content: 'Active', - severity: 'success' - } + content: 'Active', + severity: 'success' + } : { - content: 'Inactive', - severity: 'danger' - } + content: 'Inactive', + severity: 'danger' + } return parsedStatus } @@ -65,14 +65,15 @@ const adapt = async (httpResponse) => { waf: 'WAF Events' } - const templates_ids = httpResponse.body?.results.reduce((accumulator, current) => { - if (current.template_id && !accumulator.includes(current.template_id)) { - accumulator.push(current.template_id) - } - return accumulator - }, []) + const templatesIDs = + httpResponse.body?.results?.reduce((accumulator, current) => { + if (current.template_id && !accumulator.includes(current.template_id)) { + accumulator.push(current.template_id) + } + return accumulator + }, []) || [] - const mapTemplateId = await getTemplateById(templates_ids) + const mapTemplateId = await getTemplateById(templatesIDs) const parsedDataStreams = httpResponse.body?.results?.map((dataStream) => { diff --git a/src/tests/services/data-stream-services/list-data-stream-service.test.js b/src/tests/services/data-stream-services/list-data-stream-service.test.js index f1ed5d947..8d3ee0360 100644 --- a/src/tests/services/data-stream-services/list-data-stream-service.test.js +++ b/src/tests/services/data-stream-services/list-data-stream-service.test.js @@ -163,6 +163,23 @@ describe('DataStreamServices', () => { expect(result).toEqual([]) }) + it('should call api with 403 not permission', async () => { + vi.spyOn(AxiosHttpClientAdapter, 'request').mockResolvedValueOnce({ + statusCode: 403, + body: { + details: 'You do not have permission to do this action.' + } + }) + + const { sut } = makeSut() + + try { + await sut() + } catch (error) { + expect(error).toBe('You do not have permission to do this action.') + } + }) + it.each([ { statusCode: 400,