-
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-5813] fix: show name of instance function instead of function on…
… Edge App Rules Engine (#1975)
- Loading branch information
Showing
8 changed files
with
137 additions
and
11 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
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
41 changes: 41 additions & 0 deletions
41
src/services/edge-application-functions-services/v4/list-edge-functions-options-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,41 @@ | ||
import { AxiosHttpClientAdapter, parseHttpResponse } from '@/services/axios/AxiosHttpClientAdapter' | ||
import { makeEdgeFunctionsBaseUrl } from './make-edge-function-base-url' | ||
import { makeListServiceQueryParams } from '@/helpers/make-list-service-query-params' | ||
|
||
export const listFunctionsServiceOptions = async ({ | ||
id, | ||
ordering = 'name', | ||
page = 1, | ||
pageSize = 100, | ||
search = '', | ||
fields = '' | ||
}) => { | ||
const searchParams = makeListServiceQueryParams({ ordering, page, pageSize, search, fields }) | ||
let httpResponse = await AxiosHttpClientAdapter.request({ | ||
url: `${makeEdgeFunctionsBaseUrl()}/${id}/functions?${searchParams.toString()}`, | ||
method: 'GET' | ||
}) | ||
|
||
httpResponse = adapt(httpResponse) | ||
|
||
return parseHttpResponse(httpResponse) | ||
} | ||
|
||
const adapt = (httpResponse) => { | ||
const bodyResults = httpResponse.body.results | ||
|
||
const parsedFunctions = bodyResults?.map((edgeApplicationFunction) => { | ||
return { | ||
id: edgeApplicationFunction.id.toString(), | ||
name: edgeApplicationFunction.name | ||
} | ||
}) | ||
|
||
const count = httpResponse.body.count | ||
|
||
return { | ||
count, | ||
body: parsedFunctions, | ||
statusCode: httpResponse.statusCode | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...rvices/edge-application-functions-services/v4/list-edge-functions-options-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,81 @@ | ||
import { AxiosHttpClientAdapter } from '@/services/axios/AxiosHttpClientAdapter' | ||
import { listFunctionsServiceOptions } from '@/services/edge-application-functions-services/v4' | ||
import { describe, expect, it, vi } from 'vitest' | ||
|
||
const API_VERSION = 'v4' | ||
const EDGE_APPLICATION_ID = 123 | ||
|
||
const query = { | ||
page: 1, | ||
pageSize: 30, | ||
search: 'test01' | ||
} | ||
|
||
const fixtures = { | ||
functionsInstance: { | ||
name: 'function instance name', | ||
json_args: {}, | ||
edge_function: 321, | ||
id: 123, | ||
initiator_type: 'teste' | ||
} | ||
} | ||
|
||
const makeSut = () => { | ||
const sut = listFunctionsServiceOptions | ||
return { sut } | ||
} | ||
|
||
describe('EdgeApplicationFunctionsServices', () => { | ||
vi.restoreAllMocks() | ||
|
||
it('should call API with correct params', async () => { | ||
const requestSpy = vi.spyOn(AxiosHttpClientAdapter, 'request').mockResolvedValueOnce({ | ||
statusCode: 200, | ||
body: { results: [] }, | ||
count: 0 | ||
}) | ||
const { sut } = makeSut() | ||
|
||
await sut({ id: EDGE_APPLICATION_ID }) | ||
|
||
expect(requestSpy).toHaveBeenCalledWith({ | ||
url: `${API_VERSION}/edge_application/applications/123/functions?ordering=name&page=1&page_size=100&fields=&search=`, | ||
method: 'GET' | ||
}) | ||
}) | ||
|
||
it('should call API with correct search params', async () => { | ||
const requestSpy = vi.spyOn(AxiosHttpClientAdapter, 'request').mockResolvedValueOnce({ | ||
statusCode: 200, | ||
body: { results: [] }, | ||
count: 0 | ||
}) | ||
const { sut } = makeSut() | ||
|
||
await sut({ id: EDGE_APPLICATION_ID, ...query }) | ||
|
||
expect(requestSpy).toHaveBeenCalledWith({ | ||
url: `${API_VERSION}/edge_application/applications/123/functions?ordering=name&page=1&page_size=30&fields=&search=test01`, | ||
method: 'GET' | ||
}) | ||
}) | ||
|
||
it('should correctly parse all returned edge firewall function instances', async () => { | ||
vi.spyOn(AxiosHttpClientAdapter, 'request').mockResolvedValueOnce({ | ||
statusCode: 200, | ||
body: { results: [fixtures.functionsInstance] }, | ||
count: 1 | ||
}) | ||
const { sut } = makeSut() | ||
|
||
const result = await sut({ id: EDGE_APPLICATION_ID }) | ||
|
||
expect(result).toEqual([ | ||
{ | ||
id: fixtures.functionsInstance.id.toString(), | ||
name: fixtures.functionsInstance.name | ||
} | ||
]) | ||
}) | ||
}) |
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