Skip to content

Commit

Permalink
[UXE-5459] feat: update edge node list view and service import to v4 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpaulo-azion authored Feb 3, 2025
1 parent eb71aa4 commit b201da6
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/router/routes/edge-node-routes/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as EdgeNodeService from '@/services/edge-node-services'
import * as EdgeNodeServiceV4 from '@/services/edge-node-services/v4'
import * as ServiceEdgeNode from '@/services/edge-node-service-services'
import * as Helpers from '@/helpers'

Expand All @@ -12,7 +13,7 @@ export const edgeNodeRoutes = {
name: 'list-edge-node',
component: () => import('@views/EdgeNode/ListView.vue'),
props: {
listEdgeNodeService: EdgeNodeService.listEdgeNodeService,
listEdgeNodeService: EdgeNodeServiceV4.listEdgeNodeService,
deleteEdgeNodeService: EdgeNodeService.deleteEdgeNodeService,
documentationService: Helpers.documentationCatalog.edgeNodes
},
Expand Down
6 changes: 6 additions & 0 deletions src/services/edge-node-services/v4/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { listEdgeNodeService } from './list-edge-node-service'

/**
* @type {ExportedServicesType}
*/
export { listEdgeNodeService }
50 changes: 50 additions & 0 deletions src/services/edge-node-services/v4/list-edge-node-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { AxiosHttpClientAdapter, parseHttpResponse } from '@/services/axios/AxiosHttpClientAdapter'
import { makeEdgeNodeBaseUrl } from './make-edge-node-base-url'
import { makeListServiceQueryParams } from '@/helpers/make-list-service-query-params'

export const listEdgeNodeService = async ({
search = '',
fields = '',
ordering = 'name',
page = 1,
pageSize = 10
}) => {
const searchParams = makeListServiceQueryParams({ fields, ordering, page, pageSize, search })
let httpResponse = await AxiosHttpClientAdapter.request({
url: `${makeEdgeNodeBaseUrl()}?${searchParams.toString()}`,
method: 'GET'
})

httpResponse = adapt(httpResponse)

return parseHttpResponse(httpResponse)
}

const nodeStatusMap = {
authorized: 'Authorized',
waiting_authorization: 'Waiting Authorization'
}

const adapt = (httpResponse) => {
const nodes = httpResponse.body.results

const isArray = Array.isArray(nodes)

const parsedEdgeNodes =
isArray && nodes.length
? nodes.map((element) => ({
id: element.id,
name: element.name,
hashId: element.hash_id,
status: {
content: nodeStatusMap[element.status],
severity: element.status === 'authorized' ? 'success' : 'warning'
}
}))
: []

return {
body: parsedEdgeNodes,
statusCode: httpResponse.statusCode
}
}
4 changes: 4 additions & 0 deletions src/services/edge-node-services/v4/make-edge-node-base-url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const makeEdgeNodeBaseUrl = () => {
const version = 'v4'
return `${version}/edge_orchestrator/edge_nodes`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { AxiosHttpClientAdapter } from '@/services/axios/AxiosHttpClientAdapter'
import { listEdgeNodeService } from '@/services/edge-node-services/v4'
import { describe, expect, it, vi } from 'vitest'
import { localeMock } from '@/tests/utils/localeMock'

const fixtures = {
edgeNodeMock: {
id: 1239875,
name: 'JS Edge Node',
hash_id: '128973k#%(J&%@$',
status: 'waiting_authorization'
}
}

const makeSut = () => {
const sut = listEdgeNodeService

return {
sut
}
}

describe('EdgeNodeServicesV4', () => {
it('should call api with correct params', async () => {
const requestSpy = vi.spyOn(AxiosHttpClientAdapter, 'request').mockResolvedValueOnce({
statusCode: 200,
body: { nodes: [] }
})
const { sut } = makeSut()
const version = 'v4'
await sut({})

expect(requestSpy).toHaveBeenCalledWith({
url: `${version}/edge_orchestrator/edge_nodes?ordering=name&page=1&page_size=10&fields=&search=`,
method: 'GET'
})
})

it('should parsed correctly all returned firewalls', async () => {
localeMock()
vi.setSystemTime(new Date(2023, 10, 10, 10))
vi.spyOn(AxiosHttpClientAdapter, 'request').mockResolvedValueOnce({
statusCode: 200,
body: { results: [fixtures.edgeNodeMock] }
})
const { sut } = makeSut()

const result = await sut({})

expect(result).toEqual([
{
id: fixtures.edgeNodeMock.id,
name: fixtures.edgeNodeMock.name,
hashId: fixtures.edgeNodeMock.hash_id,
status: {
content: 'Waiting Authorization',
severity: 'warning'
}
}
])
})
})
7 changes: 0 additions & 7 deletions src/views/EdgeNode/ListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@
field: 'hashId',
header: 'Hash ID'
},
{
field: 'groups',
header: 'Group',
type: 'component',
component: (columnData) =>
columnBuilder({ data: columnData, columnAppearance: 'expand-column' })
},
{
field: 'status',
header: 'Status',
Expand Down

0 comments on commit b201da6

Please sign in to comment.