-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UXE-5459] feat: update edge node list view and service import to v4 (#…
- Loading branch information
1 parent
eb71aa4
commit b201da6
Showing
6 changed files
with
124 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
50
src/services/edge-node-services/v4/list-edge-node-service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
4
src/services/edge-node-services/v4/make-edge-node-base-url.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | ||
} |
62 changes: 62 additions & 0 deletions
62
src/tests/services/edge-node-services/v4/list-edge-node-service.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} | ||
} | ||
]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters