Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 64 additions & 28 deletions apps/meteor/app/api/server/ApiClass.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,72 @@ import type { APIClass, ExtractRoutesFromAPI } from './ApiClass';
type Expect<T extends true> = T;
type ShallowEqual<X, Y> = X extends Y ? (Y extends X ? true : false) : false;

type API = APIClass<
'/v1',
{
method: 'GET';
path: '/v1/endpoint.test';
response: {
200: ValidateFunction<
PaginatedResult<{
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;
});
Comment on lines +9 to +76
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.

});
Loading