-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into create-endpoint-for-updating-option-list-id
- Loading branch information
Showing
21 changed files
with
431 additions
and
183 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ jobs: | |
resource-adm | ||
resource-registry | ||
settings | ||
studio-root | ||
subform | ||
testing | ||
text | ||
|
60 changes: 60 additions & 0 deletions
60
frontend/app-development/hooks/mutations/useUpdateSelectedMaskinportenScopesMutation.test.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,60 @@ | ||
import { queriesMock } from 'app-shared/mocks/queriesMock'; | ||
import { renderHookWithProviders } from '../../test/mocks'; | ||
import { useUpdateSelectedMaskinportenScopesMutation } from './useUpdateSelectedMaskinportenScopesMutation'; | ||
import { waitFor } from '@testing-library/react'; | ||
import { QueryKey } from 'app-shared/types/QueryKey'; | ||
import { createQueryClientMock } from 'app-shared/mocks/queryClientMock'; | ||
import type { QueryClient } from '@tanstack/react-query'; | ||
import { app, org } from '@studio/testing/testids'; | ||
import { | ||
type MaskinportenScope, | ||
type MaskinportenScopes, | ||
} from 'app-shared/types/MaskinportenScope'; | ||
|
||
const scopeMock1: MaskinportenScope = { | ||
scope: 'scope1', | ||
description: 'description1', | ||
}; | ||
const scopeMock2: MaskinportenScope = { | ||
scope: 'scope2', | ||
description: 'description2', | ||
}; | ||
const maskinportenScopes: MaskinportenScopes = { scopes: [scopeMock1, scopeMock2] }; | ||
|
||
describe('useUpdateSelectedMaskinportenScopesMutation', () => { | ||
it('calls updateSelectedMaskinportenScopes with correct arguments and payload', async () => { | ||
await renderHook(); | ||
|
||
expect(queriesMock.updateSelectedMaskinportenScopes).toHaveBeenCalledTimes(1); | ||
expect(queriesMock.updateSelectedMaskinportenScopes).toHaveBeenCalledWith( | ||
org, | ||
app, | ||
maskinportenScopes, | ||
); | ||
}); | ||
|
||
it('invalidates metadata queries when update is successful', async () => { | ||
const queryClient = createQueryClientMock(); | ||
const invalidateQueriesSpy = jest.spyOn(queryClient, 'invalidateQueries'); | ||
|
||
await renderHook({ queryClient }); | ||
|
||
expect(invalidateQueriesSpy).toHaveBeenCalledTimes(1); | ||
expect(invalidateQueriesSpy).toHaveBeenCalledWith({ | ||
queryKey: [QueryKey.SelectedAppScopes, org, app], | ||
}); | ||
}); | ||
}); | ||
|
||
const renderHook = async ({ | ||
queryClient, | ||
}: { | ||
queryClient?: QueryClient; | ||
} = {}) => { | ||
const result = renderHookWithProviders( | ||
{}, | ||
queryClient, | ||
)(() => useUpdateSelectedMaskinportenScopesMutation()).renderHookResult.result; | ||
await waitFor(() => result.current.mutateAsync(maskinportenScopes)); | ||
expect(result.current.isSuccess).toBe(true); | ||
}; |
18 changes: 18 additions & 0 deletions
18
frontend/app-development/hooks/mutations/useUpdateSelectedMaskinportenScopesMutation.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,18 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import { useServicesContext } from 'app-shared/contexts/ServicesContext'; | ||
import { useStudioEnvironmentParams } from 'app-shared/hooks/useStudioEnvironmentParams'; | ||
import { type MaskinportenScopes } from 'app-shared/types/MaskinportenScope'; | ||
import { QueryKey } from 'app-shared/types/QueryKey'; | ||
|
||
export const useUpdateSelectedMaskinportenScopesMutation = () => { | ||
const queryClient = useQueryClient(); | ||
const { org, app } = useStudioEnvironmentParams(); | ||
const { updateSelectedMaskinportenScopes } = useServicesContext(); | ||
|
||
return useMutation({ | ||
mutationFn: (payload: MaskinportenScopes) => | ||
updateSelectedMaskinportenScopes(org, app, payload), | ||
onSuccess: () => | ||
queryClient.invalidateQueries({ queryKey: [QueryKey.SelectedAppScopes, org, app] }), | ||
}); | ||
}; |
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 |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { QueryKey } from 'app-shared/types/QueryKey'; | ||
import { useServicesContext } from 'app-shared/contexts/ServicesContext'; | ||
import { type MaskinportenScope } from 'app-shared/types/MaskinportenScope'; | ||
import { type MaskinportenScopes } from 'app-shared/types/MaskinportenScope'; | ||
import { useStudioEnvironmentParams } from 'app-shared/hooks/useStudioEnvironmentParams'; | ||
|
||
export const useGetScopesQuery = () => { | ||
const { org, app } = useStudioEnvironmentParams(); | ||
const { getMaskinportenScopes } = useServicesContext(); | ||
return useQuery<MaskinportenScope[]>({ | ||
return useQuery<MaskinportenScopes>({ | ||
queryKey: [QueryKey.AppScopes], | ||
queryFn: () => getMaskinportenScopes(), | ||
queryFn: () => getMaskinportenScopes(org, app), | ||
}); | ||
}; |
10 changes: 6 additions & 4 deletions
10
frontend/app-development/hooks/queries/useGetSelectedScopesQuery.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 |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { QueryKey } from 'app-shared/types/QueryKey'; | ||
import { useServicesContext } from 'app-shared/contexts/ServicesContext'; | ||
import { type MaskinportenScope } from 'app-shared/types/MaskinportenScope'; | ||
import { type MaskinportenScopes } from 'app-shared/types/MaskinportenScope'; | ||
import { useStudioEnvironmentParams } from 'app-shared/hooks/useStudioEnvironmentParams'; | ||
|
||
export const useGetSelectedScopesQuery = () => { | ||
const { org, app } = useStudioEnvironmentParams(); | ||
const { getSelectedMaskinportenScopes } = useServicesContext(); | ||
return useQuery<MaskinportenScope[]>({ | ||
queryKey: [QueryKey.SelectedAppScopes], | ||
queryFn: () => getSelectedMaskinportenScopes(), | ||
return useQuery<MaskinportenScopes>({ | ||
queryKey: [QueryKey.SelectedAppScopes, org, app], | ||
queryFn: () => getSelectedMaskinportenScopes(org, app), | ||
}); | ||
}; |
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
Oops, something went wrong.