Skip to content

Commit

Permalink
refactor(28843): add react query hooks for all south and north mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
vanch3d committed Dec 11, 2024
1 parent 930ca6e commit ac09dd2
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 0 deletions.
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',
}),
],
})
})
})
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(),
})
}
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',
}),
],
})
})
})
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(),
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ export const mappingHandlers = [
return HttpResponse.json<NorthboundMappingList>({ items: [MOCK_NORTHBOUND_MAPPING] }, { status: 200 })
}),

http.get<{ adapterId: string }>('*/management/protocol-adapters/northboundMappings', () => {
return HttpResponse.json<NorthboundMappingList>({ items: [MOCK_NORTHBOUND_MAPPING] }, { status: 200 })
}),

http.get<{ adapterId: string }>('*/management/protocol-adapters/southboundMappings', () => {
return HttpResponse.json<SouthboundMappingList>({ items: [MOCK_SOUTHBOUND_MAPPING] }, { status: 200 })
}),

http.put<{ adapterId: string }>(
'*/management/protocol-adapters/adapters/:adapterId/northboundMappings',
async ({ params, request }) => {
Expand Down

0 comments on commit ac09dd2

Please sign in to comment.