Skip to content

Commit

Permalink
[UXE-6102] fix: improve status parsing and handle optional results in…
Browse files Browse the repository at this point in the history
… list data stream (#2091)
  • Loading branch information
lucasmendes21 authored Jan 24, 2025
1 parent 580a2bb commit 64f1a80
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/services/data-stream-services/list-data-stream-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 64f1a80

Please sign in to comment.