Skip to content

Conversation

@ahmed-n-abdeltwab
Copy link
Contributor

@ahmed-n-abdeltwab ahmed-n-abdeltwab commented Jun 26, 2025

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:

$ yarn .testunit:client apps/meteor/app/api/server/ApiClass.spec.ts
 PASS   server  app/api/server/ApiClass.spec.ts
  ExtractRoutesFromAPI type utility
    ✓ Should return the expected type for GET (7 ms)
    ✓ Should return the expected type for POST

----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------|---------|----------|---------|---------|-------------------
All files |       0 |        0 |       0 |       0 |                   
----------|---------|----------|---------|---------|-------------------
Test Suites: 1 passed, 1 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        1.983 s
Ran all test suites matching apps/meteor/app/api/server/ApiClass.spec.ts.

@ahmed-n-abdeltwab ahmed-n-abdeltwab requested review from a team as code owners June 26, 2025 13:35
@changeset-bot
Copy link

changeset-bot bot commented Jun 26, 2025

⚠️ No Changeset found

Latest commit: 302d562

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Jun 26, 2025

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

Comment on lines 74 to 82
[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;
Copy link
Contributor Author

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.

Comment on lines 673 to 676
| ({
method: 'POST';
path: TPathPattern;
} & Omit<TOptions, 'response'>)
Copy link
Contributor Author

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.

Comment on lines +9 to +76
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;
});
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants