-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from Hain-tain/feat/templates_UD_api
템플릿 수정, 삭제 api 요청 기능 추가
- Loading branch information
Showing
7 changed files
with
111 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
import { renderHook, waitFor } from '@testing-library/react'; | ||
import { PropsWithChildren } from 'react'; | ||
import { useTemplateDeleteQuery } from './useTemplateDeleteQuery'; | ||
|
||
const queryClient = new QueryClient(); | ||
|
||
const queryWrapper = ({ children }: PropsWithChildren) => ( | ||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
); | ||
|
||
describe('useTemplateDeleteQuery', () => { | ||
it('templates을 삭제할 수 있다.', async () => { | ||
const { result } = renderHook(() => useTemplateDeleteQuery(2024), { wrapper: queryWrapper }); | ||
|
||
await result.current.mutateAsync(); | ||
|
||
await waitFor(() => { | ||
expect(result.current.isSuccess).toBe(true); | ||
}); | ||
}); | ||
}); |
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 { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import { QUERY_KEY } from '@/api/queryKeys'; | ||
import { deleteTemplate } from '@/api/templates'; | ||
|
||
export const useTemplateDeleteQuery = (id: number) => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: () => deleteTemplate(id), | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: [QUERY_KEY.TEMPLATE_LIST] }); | ||
}, | ||
}); | ||
}; |
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,36 @@ | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
import { renderHook, waitFor } from '@testing-library/react'; | ||
import { PropsWithChildren } from 'react'; | ||
import { TemplateEditRequest } from '@/types/template'; | ||
import { useTemplateEditQuery } from './useTemplateEditQuery'; | ||
|
||
const queryClient = new QueryClient(); | ||
|
||
const queryWrapper = ({ children }: PropsWithChildren) => ( | ||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
); | ||
|
||
describe('useTemplateEditQuery', () => { | ||
it('templates울 수정할 수 있다.', async () => { | ||
const { result } = renderHook(() => useTemplateEditQuery(2024), { wrapper: queryWrapper }); | ||
|
||
const template: TemplateEditRequest = { | ||
title: 'editTemplate', | ||
createSnippets: [], | ||
updateSnippets: [ | ||
{ | ||
filename: 'filename1.txt', | ||
content: 'content edit', | ||
ordinal: 1, | ||
}, | ||
], | ||
deleteSnippetIds: [], | ||
}; | ||
|
||
await result.current.mutateAsync({ id: 2024, template }); | ||
|
||
await waitFor(() => { | ||
expect(result.current.isSuccess).toBe(true); | ||
}); | ||
}); | ||
}); |
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 { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import { QUERY_KEY } from '@/api/queryKeys'; | ||
import { editTemplate } from '@/api/templates'; | ||
|
||
export const useTemplateEditQuery = (id: number) => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: editTemplate, | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: [QUERY_KEY.TEMPLATE, id] }); | ||
}, | ||
}); | ||
}; |
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