-
Notifications
You must be signed in to change notification settings - Fork 13.1k
test: POST with extract routes from API type definition #36309
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
base: develop
Are you sure you want to change the base?
test: POST with extract routes from API type definition #36309
Conversation
|
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
0f3ca8d to
1c589b8
Compare
| [K2 in TRoute['method']]: K2 extends 'GET' | ||
| ? (params: ExtractValidation<TRoute['query']>) => ExtractValidation<TRoute['response'][200]> | ||
| : ( | ||
| params: ExtractValidation<TRoute['body']>, | ||
| ) => 200 extends keyof TRoute['response'] | ||
| ? ExtractValidation<TRoute['response'][200]> | ||
| : 201 extends keyof TRoute['response'] | ||
| ? ExtractValidation<TRoute['response'][201]> | ||
| : never; |
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.
This was my update from the previous PR #36246, but I didn't want to push it back then, as the PR was ready to merge.
| | ({ | ||
| method: 'POST'; | ||
| path: TPathPattern; | ||
| } & Omit<TOptions, 'response'>) |
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 removed the omit from the return post function, as it is no longer important. We have the same type, but with the addition of TOptions without removing the response from it.
| describe('ExtractRoutesFromAPI type utility', () => { | ||
| it('Should return the expected type for GET', () => { | ||
| type API = APIClass< | ||
| '/v1', | ||
| { | ||
| method: 'GET'; | ||
| path: '/v1/endpoint.test'; | ||
| response: { | ||
| 200: ValidateFunction< | ||
| PaginatedResult<{ | ||
| sounds: string[]; | ||
| }> | ||
| >; | ||
| }; | ||
| query: ValidateFunction<{ | ||
| query: string; | ||
| }>; | ||
| authRequired: true; | ||
| } | ||
| >; | ||
| type test = Expect< | ||
| ShallowEqual< | ||
| ReturnType<ExtractRoutesFromAPI<API>['/v1/endpoint.test']['GET']>, | ||
| { | ||
| count: number; | ||
| offset: number; | ||
| total: number; | ||
| sounds: string[]; | ||
| }> | ||
| >; | ||
| }; | ||
| query: ValidateFunction<{ | ||
| query: string; | ||
| }>; | ||
| authRequired: true; | ||
| } | ||
| >; | ||
| } | ||
| > | ||
| >; | ||
|
|
||
| true as test; | ||
| }); | ||
|
|
||
| it('Should return the expected type', () => { | ||
| type test = Expect< | ||
| ShallowEqual< | ||
| ReturnType<ExtractRoutesFromAPI<API>['/v1/endpoint.test']['GET']>, | ||
| it('Should return the expected type for POST', () => { | ||
| type API = APIClass< | ||
| '/v1', | ||
| { | ||
| count: number; | ||
| offset: number; | ||
| total: number; | ||
| sounds: string[]; | ||
| method: 'POST'; | ||
| path: '/v1/endpoint.test'; | ||
| response: { | ||
| 200: ValidateFunction< | ||
| PaginatedResult<{ | ||
| sounds: string[]; | ||
| }> | ||
| >; | ||
| }; | ||
| body: ValidateFunction<{ | ||
| query: string; | ||
| }>; | ||
| authRequired: true; | ||
| } | ||
| > | ||
| >; | ||
| true as test; | ||
| >; | ||
| type test = Expect< | ||
| ShallowEqual< | ||
| ReturnType<ExtractRoutesFromAPI<API>['/v1/endpoint.test']['POST']>, | ||
| { | ||
| count: number; | ||
| offset: number; | ||
| total: number; | ||
| sounds: string[]; | ||
| } | ||
| > | ||
| >; | ||
|
|
||
| true as 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.
Here, I wrap the two tests together with describe and add the expected return type from the POST API.
8478dde to
302d562
Compare
Description:
Enhance type definitions and validation in APIClass and ConvertToRoute for better clarity and response handling. Fix the issue of repeated deactivation emails sent to inactive users. Update dependencies and improve test coverage for API response types.
tests: