-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
convert fetch api call to rtk mutation #529
base: develop
Are you sure you want to change the base?
convert fetch api call to rtk mutation #529
Conversation
mayurlalwani
commented
May 5, 2023
•
edited
edited
- Created mutation for update card content.
- Converted fetch api call of update card content to RTK in helper function.
- Wrote test for RTK.
@mayurlalwani is attempting to deploy a commit to the RDS-Team Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please write tests for the functionality, and description for the task.
src/app/services/tasksApi.ts
Outdated
@@ -18,7 +19,20 @@ export const tasksApi = api.injectEndpoints({ | |||
query: () => '/tasks/mine', | |||
providesTags: ['Tasks'], | |||
}), | |||
updateCardContent: builder.mutation({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think will this file would be the right place to write this API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this component was related to tasks, so I added this API in this file. Should I create a new file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the unit test for the funcitonality already exists. Should I write unit test for this helper function - "updateCardContent"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the file is okay but the naming doesn't clearly indicate what this function does, read what it is doing here
url: `"${TASKS_URL}/${id}"`,
method: 'PATCH',
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, we are writing tests for this RTK hook also "updateCardContent" and the unit tests will also change because of the change in the implementation of the API call.
47d7e04
to
e9a18d3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address the change request mentioned by bhavika and also write the test cases for it
e9a18d3
to
0942865
Compare
0942865
to
b834d29
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything looks good to me
@@ -95,4 +105,58 @@ describe('useUpdateTask hook', () => { | |||
expect(setTasks).toHaveBeenCalled(); | |||
expect(setTasks).toHaveBeenLastCalledWith(groupedTasks); | |||
}); | |||
|
|||
test('Should update task details by id', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please make a separate file for this , it should not go in this file
id: '1', | ||
cardDetails: { | ||
id: '123', | ||
lossRate: { | ||
dinero: 10, | ||
neelam: 5, | ||
}, | ||
links: [''], | ||
completionAward: { | ||
dinero: 110, | ||
neelam: 10, | ||
}, | ||
dependsOn: [], | ||
assignee: 'john', | ||
startedOn: '1618790400', | ||
isNoteworthy: true, | ||
title: 'Test', | ||
purpose: '', | ||
percentCompleted: 0, | ||
endsOn: '1618790400', | ||
status: 'progress', | ||
featureUrl: 'progress', | ||
type: 'feature', | ||
createdBy: 'sam', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taking out this data into a variable will make the test easily readable
function onSeeMoreTasksHandler() { | ||
setTasksLimit((prevLimit) => prevLimit + ADD_MORE_TASKS_LIMIT); | ||
} | ||
async function onContentChangeHandler(id: string, cardDetails: any) { | ||
if (!isEditable || !updateCardContent) return; | ||
updateCardContent(id, cardDetails); | ||
if (!isEditable || !updateTaskDetailsById) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please check is !updateTaskDetailsById
required here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not required, I will remove it.
f3cc656
to
8888916
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, ask Bhavika to approve, I will approve after she approves
8888916
to
e581013
Compare
e581013
to
1462973
Compare