-
Notifications
You must be signed in to change notification settings - Fork 5
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
Feat :Implement & Apply API client method for rename group feature #242
Feat :Implement & Apply API client method for rename group feature #242
Conversation
*/ | ||
export const createGroup = async (params: ICreateGroupParams): Promise<string> => { | ||
export const postCreateGroup = async ( | ||
payload: IPostCreateGroupPayload, |
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.
Just changed the variable name from params
to payload
because it's defined as payload
in web api doc
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.
@kanta1207
Thank you for your work! Overall, your implementation has no problem!
As for code styling and conventions, I added some comments. Please take a look when you have a moment.
By the way, your code reminded me that I missed TSDocs for actions and API clients of the foods feature. I will fix them in my next PR
/** | ||
* Process the form submission. | ||
* @param values - The form values | ||
*/ | ||
const processSubmit: SubmitHandler<Inputs> = async (values) => { | ||
const processSubmit: SubmitHandler<RenameGroupInputs> = async (values) => { |
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.
Can you please avoid using nested if
statements?
|
||
import { zodResolver } from '@hookform/resolvers/zod'; | ||
import { FC, useEffect } from 'react'; | ||
import { SubmitHandler, useForm } from 'react-hook-form'; | ||
import { z } from 'zod'; | ||
|
||
import { createGroup } from '../../lib/actions'; | ||
import { createGroupFormSchema, CreateGroupInputs } from '../../lib/schemas'; |
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.
Could you please avoid using relative paths except it's in the same directory ./
?
src/features/groups/lib/actions.ts
Outdated
} from './schemas'; | ||
|
||
/** | ||
* Method to create a group. |
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 term "method" is only used to describe functions that are defined in an object or a class. There are several more lines that use the word "method" incorrectly.
src/features/groups/lib/actions.ts
Outdated
|
||
/** | ||
* Method to create a group. | ||
* @param inputs - The payload for the method. |
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.
In terms of API, the word "payload" seems the actual data transported between the backend and the frontend.
Simply put, it is the body of your HTTP request and response message.
Since the param inputs
here is just plain user's inputs, using the word "payload" is technically incorrect.
See: What is Payload?
*There are a few more lines that use the word "payload" in the wrong way.
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.
Yeah you're right, inputs in here is just user inputs... I renamed them!
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.
I like how you organized this file. I will follow your conversions in my next PR.
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.
jest.mock('@/lib/api/common/client/commonUtils.client', () => ({
to
jest.mock('@/lib/api/common/client', () => ({
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 would be more helpful if you could explicitly state the targets of this test.
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.
/**
* @template
* @return
*/
These are non-standard @tags
since they are not defined in the official TSDoc documents. The correct usage is @returns
(plural) instead of @return
. If you find more in other files, could you please fix them together?
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.
@kanta1207 Thank you for fixing it. However, the @template
is not a standard tag, either. Could you find all and fix them, please?
IPostCreateGroupApiResponse, | ||
IPostCreateGroupPayload, | ||
putRenameGroup, | ||
} from './groupApiClient.client'; |
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.
Combine the imports:
import { postCreateGroup } from '@/lib/api/group/client';
import {
IPostCreateGroupApiResponse,
IPostCreateGroupPayload,
putRenameGroup,
} from './groupApiClient.client';
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.
You're right, and I also forgot to index the exports...
I fixed them!
const result = await createGroup(mockInvalidInputs); | ||
|
||
// Assert | ||
expect(result).toEqual(Err('Validation failed')); |
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 would be better to include this assertion. Because calling the postCreateGroup
before the error is thrown might result in unintentional creation of data.
expect(postCreateGroup).not.toHaveBeenCalled();
const result = await renameGroup(mockGroupId, mockInvalidInputs); | ||
|
||
// Assert | ||
expect(result).toEqual(Err('Validation failed')); |
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.
Same for here.
}; | ||
describe('postCreateGroup', () => { | ||
// Arrange mock data | ||
const mockPayload: IPostCreateGroupPayload = { groupName: 'Shared-house' }; | ||
it('successfully creates a group', 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.
Could you add a line break before each it()
and describe
to improve readability, please?
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.
@kanta1207 Thank you for fixing it, but I found one in the src/features/groups/lib/actions.test.ts
, too.
@nick-y-ito |
@kanta1207 |
@nick-y-ito |
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.
@kanta1207
Everything looks good to me now :)
Thank you very much for your excellent work!!
Overview
RenameGroupForm
.Changes
result-ts-type
.action
andschema
files for create & rename group.Review points
Assignee Checklist:
Reviewer Checklist: