Testing
Creating a server-side caller for your ptsq application can provide you with a type-safe server client that doesn't perform any HTTP requests. This client allows you to simulate interactions with your backend API programmatically, enabling thorough testing of your application's logic and behavior without the need to set up a separate HTTP server.
With this type-safe server client, you can directly invoke your resolver functions and middleware, providing input data and capturing output results for validation. By bypassing the HTTP layer, you can focus exclusively on testing your backend application's functionality in a controlled environment, ensuring that it behaves correctly under various conditions and scenarios.
This approach offers a convenient and efficient way to validate the behavior of your ptsq application's backend logic, helping you identify and resolve issues early in the development process while ensuring the overall quality and reliability of your application.
const testBaseRouter = baseRouter.createServerSideCaller({
/* ctx */,
req: {} as any,
res: {} as any,
user: new User({ admin: true }) // fake or seeded user for testing
});
/**
* Access queries and mutations as with the client but without any server creation and http calls
*/
const response /* string */ = await testBaseRouter.greetings.query({
/* type-safe as client */
name: /* string */ 'John'
});