Skip to content
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

Merged

Conversation

kanta1207
Copy link
Member

@kanta1207 kanta1207 commented Feb 19, 2024

Overview

  • Implement rename api client, and apply it to RenameGroupForm.

Changes

  • Implement api client for rename group feature.
  • Refactor create group api client, using result-ts-type.
  • Add action and schema files for create & rename group.
  • Add test for group api client methods and action

Review points

  • If the code is easy to read, well commented
  • If create and rename group api client are working properly

Assignee Checklist:

  • The naming convention of the PR title is correct (See the comment at the top of this template)
  • The base branch is correct (See: Types of Branches)
  • The branch name follows the Branch Naming Conventions
  • The correct assignees and reviewers have been designated for this PR
  • The coding style follows the Coding Style Guide
  • All the related issues are associated with this PR
  • All criteria in the associated issues are met (please tick the checkboxes)
  • My changes do not generate new warnings or errors (especially in the console)

Reviewer Checklist:

  • Double-check the "Assignee Checklist"
  • The code follows the generic best practices and our Coding Style Guide
  • The code is well-commented and easy to understand
  • The UI changes accurately reflect the provided design

@kanta1207 kanta1207 linked an issue Feb 19, 2024 that may be closed by this pull request
2 tasks
@kanta1207 kanta1207 self-assigned this Feb 19, 2024
*/
export const createGroup = async (params: ICreateGroupParams): Promise<string> => {
export const postCreateGroup = async (
payload: IPostCreateGroupPayload,
Copy link
Member Author

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

@kanta1207 kanta1207 marked this pull request as ready for review February 19, 2024 04:01
Copy link
Member

@nick-y-ito nick-y-ito left a 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) => {
Copy link
Member

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';
Copy link
Member

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 ./?

} from './schemas';

/**
* Method to create a group.
Copy link
Member

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.


/**
* Method to create a group.
* @param inputs - The payload for the method.
Copy link
Member

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.

Copy link
Member Author

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!

Copy link
Member

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.

Copy link
Member

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', () => ({

Copy link
Member

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.

Copy link
Member

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?

Copy link
Member

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';
Copy link
Member

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';

Copy link
Member Author

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'));
Copy link
Member

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'));
Copy link
Member

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 () => {
Copy link
Member

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?

Copy link
Member

@nick-y-ito nick-y-ito Feb 20, 2024

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.

@kanta1207
Copy link
Member Author

@nick-y-ito
Thank you for your review!
I addressed the issues you mentioned, so please take a relook at them when you have a moment 🙏

@nick-y-ito
Copy link
Member

nick-y-ito commented Feb 20, 2024

@kanta1207
Thank you for addressing my previous comments. However, I noticed a few small issues that were not corrected. Could you please take a second look?

@kanta1207
Copy link
Member Author

@kanta1207 Thank you for addressing my previous comments. However, I noticed a few small issues that were not corrected. Could you please take a second look?

@nick-y-ito
Sorry for missing some points 🙏
I addressed them, please kindly take a look!

Copy link
Member

@nick-y-ito nick-y-ito left a 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!!

@kanta1207 kanta1207 merged commit 3707e99 into develop Feb 20, 2024
3 checks passed
@kanta1207 kanta1207 deleted the feature/237-api-client-method-for-rename-group-feature branch February 20, 2024 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create API client method for "Rename Group" feature
2 participants