diff --git a/hivemq-edge/src/frontend/src/api/hooks/useDomainModel/useLisdtDomainNorthboundMappings.spec.ts b/hivemq-edge/src/frontend/src/api/hooks/useDomainModel/useLisdtDomainNorthboundMappings.spec.ts new file mode 100644 index 000000000..397f6eaca --- /dev/null +++ b/hivemq-edge/src/frontend/src/api/hooks/useDomainModel/useLisdtDomainNorthboundMappings.spec.ts @@ -0,0 +1,39 @@ +import { beforeEach, expect } from 'vitest' +import { renderHook, waitFor } from '@testing-library/react' + +import { server } from '@/__test-utils__/msw/mockServer.ts' +import { SimpleWrapper as wrapper } from '@/__test-utils__/hooks/SimpleWrapper.tsx' +import { type NorthboundMappingList } from '@/api/__generated__' + +import { useListDomainNorthboundMappings } from '@/api/hooks/useDomainModel/useListDomainNorthboundMappings.ts' +import { mappingHandlers } from '@/api/hooks/useProtocolAdapters/__handlers__/mapping.mocks.ts' + +describe('useListDomainNorthboundMappings', () => { + beforeEach(() => { + server.use(...mappingHandlers) + }) + + afterEach(() => { + server.resetHandlers() + }) + + it('should load the data', async () => { + const { result } = renderHook(() => useListDomainNorthboundMappings(), { wrapper }) + await waitFor(() => { + expect(result.current.isLoading).toBeFalsy() + expect(result.current.isSuccess).toBeTruthy() + }) + expect(result.current.data).toStrictEqual({ + items: [ + expect.objectContaining({ + includeTagNames: true, + includeTimestamp: true, + maxQoS: 'AT_MOST_ONCE', + messageExpiryInterval: -1000, + tagName: 'my/tag', + topic: 'my/topic', + }), + ], + }) + }) +}) diff --git a/hivemq-edge/src/frontend/src/api/hooks/useDomainModel/useListDomainNorthboundMappings.ts b/hivemq-edge/src/frontend/src/api/hooks/useDomainModel/useListDomainNorthboundMappings.ts new file mode 100644 index 000000000..4f22ed2e4 --- /dev/null +++ b/hivemq-edge/src/frontend/src/api/hooks/useDomainModel/useListDomainNorthboundMappings.ts @@ -0,0 +1,14 @@ +import { useQuery } from '@tanstack/react-query' +import { QUERY_KEYS } from '@/api/utils.ts' + +import { ApiError, type NorthboundMappingList } from '@/api/__generated__' +import { useHttpClient } from '@/api/hooks/useHttpClient/useHttpClient.ts' + +export const useListDomainNorthboundMappings = () => { + const appClient = useHttpClient() + + return useQuery({ + queryKey: [QUERY_KEYS.NORTHBOUND_MAPPINGS], + queryFn: () => appClient.protocolAdapters.getNorthboundMappings(), + }) +} diff --git a/hivemq-edge/src/frontend/src/api/hooks/useDomainModel/useListDomainSouthboundMappings.spec.ts b/hivemq-edge/src/frontend/src/api/hooks/useDomainModel/useListDomainSouthboundMappings.spec.ts new file mode 100644 index 000000000..1ce4a287b --- /dev/null +++ b/hivemq-edge/src/frontend/src/api/hooks/useDomainModel/useListDomainSouthboundMappings.spec.ts @@ -0,0 +1,43 @@ +import { beforeEach, expect } from 'vitest' +import { renderHook, waitFor } from '@testing-library/react' + +import { server } from '@/__test-utils__/msw/mockServer.ts' +import { SimpleWrapper as wrapper } from '@/__test-utils__/hooks/SimpleWrapper.tsx' +import { type NorthboundMappingList } from '@/api/__generated__' + +import { mappingHandlers } from '@/api/hooks/useProtocolAdapters/__handlers__/mapping.mocks.ts' +import { useListDomainSouthboundMappings } from '@/api/hooks/useDomainModel/useListDomainSouthboundMappings.ts' + +describe('useListDomainNorthboundMappings', () => { + beforeEach(() => { + server.use(...mappingHandlers) + }) + + afterEach(() => { + server.resetHandlers() + }) + + it('should load the data', async () => { + const { result } = renderHook(() => useListDomainSouthboundMappings(), { wrapper }) + await waitFor(() => { + expect(result.current.isLoading).toBeFalsy() + expect(result.current.isSuccess).toBeTruthy() + }) + expect(result.current.data).toStrictEqual({ + items: [ + expect.objectContaining({ + fieldMapping: { + instructions: [ + { + destination: 'lastName', + source: 'dropped-property', + }, + ], + }, + tagName: 'my/tag', + topicFilter: 'my/filter', + }), + ], + }) + }) +}) diff --git a/hivemq-edge/src/frontend/src/api/hooks/useDomainModel/useListDomainSouthboundMappings.ts b/hivemq-edge/src/frontend/src/api/hooks/useDomainModel/useListDomainSouthboundMappings.ts new file mode 100644 index 000000000..3ad30f150 --- /dev/null +++ b/hivemq-edge/src/frontend/src/api/hooks/useDomainModel/useListDomainSouthboundMappings.ts @@ -0,0 +1,14 @@ +import { useQuery } from '@tanstack/react-query' +import { QUERY_KEYS } from '@/api/utils.ts' + +import { ApiError, type SouthboundMappingList } from '@/api/__generated__' +import { useHttpClient } from '@/api/hooks/useHttpClient/useHttpClient.ts' + +export const useListDomainSouthboundMappings = () => { + const appClient = useHttpClient() + + return useQuery({ + queryKey: [QUERY_KEYS.SOUTHBOUND_MAPPINGS], + queryFn: () => appClient.protocolAdapters.getSouthboundMappings(), + }) +} diff --git a/hivemq-edge/src/frontend/src/api/hooks/useProtocolAdapters/__handlers__/mapping.mocks.ts b/hivemq-edge/src/frontend/src/api/hooks/useProtocolAdapters/__handlers__/mapping.mocks.ts index d7e38cc12..97f8ed781 100644 --- a/hivemq-edge/src/frontend/src/api/hooks/useProtocolAdapters/__handlers__/mapping.mocks.ts +++ b/hivemq-edge/src/frontend/src/api/hooks/useProtocolAdapters/__handlers__/mapping.mocks.ts @@ -39,6 +39,14 @@ export const mappingHandlers = [ return HttpResponse.json({ items: [MOCK_NORTHBOUND_MAPPING] }, { status: 200 }) }), + http.get<{ adapterId: string }>('*/management/protocol-adapters/northboundMappings', () => { + return HttpResponse.json({ items: [MOCK_NORTHBOUND_MAPPING] }, { status: 200 }) + }), + + http.get<{ adapterId: string }>('*/management/protocol-adapters/southboundMappings', () => { + return HttpResponse.json({ items: [MOCK_SOUTHBOUND_MAPPING] }, { status: 200 }) + }), + http.put<{ adapterId: string }>( '*/management/protocol-adapters/adapters/:adapterId/northboundMappings', async ({ params, request }) => {