-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(28843): add react query hooks for all south and north mappings
- Loading branch information
Showing
5 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...q-edge/src/frontend/src/api/hooks/useDomainModel/useLisdtDomainNorthboundMappings.spec.ts
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,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<NorthboundMappingList>({ | ||
items: [ | ||
expect.objectContaining({ | ||
includeTagNames: true, | ||
includeTimestamp: true, | ||
maxQoS: 'AT_MOST_ONCE', | ||
messageExpiryInterval: -1000, | ||
tagName: 'my/tag', | ||
topic: 'my/topic', | ||
}), | ||
], | ||
}) | ||
}) | ||
}) |
14 changes: 14 additions & 0 deletions
14
hivemq-edge/src/frontend/src/api/hooks/useDomainModel/useListDomainNorthboundMappings.ts
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,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<NorthboundMappingList, ApiError>({ | ||
queryKey: [QUERY_KEYS.NORTHBOUND_MAPPINGS], | ||
queryFn: () => appClient.protocolAdapters.getNorthboundMappings(), | ||
}) | ||
} |
43 changes: 43 additions & 0 deletions
43
...mq-edge/src/frontend/src/api/hooks/useDomainModel/useListDomainSouthboundMappings.spec.ts
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,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<NorthboundMappingList>({ | ||
items: [ | ||
expect.objectContaining({ | ||
fieldMapping: { | ||
instructions: [ | ||
{ | ||
destination: 'lastName', | ||
source: 'dropped-property', | ||
}, | ||
], | ||
}, | ||
tagName: 'my/tag', | ||
topicFilter: 'my/filter', | ||
}), | ||
], | ||
}) | ||
}) | ||
}) |
14 changes: 14 additions & 0 deletions
14
hivemq-edge/src/frontend/src/api/hooks/useDomainModel/useListDomainSouthboundMappings.ts
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,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<SouthboundMappingList, ApiError>({ | ||
queryKey: [QUERY_KEYS.SOUTHBOUND_MAPPINGS], | ||
queryFn: () => appClient.protocolAdapters.getSouthboundMappings(), | ||
}) | ||
} |
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