fix(core): update

This commit is contained in:
2024-02-21 18:29:35 +01:00
parent f837bb5230
commit bf81c34dbc
10 changed files with 244 additions and 108 deletions

View File

@ -4,6 +4,7 @@ import * as typedserver from '@api.global/typedserver';
import * as typedrequest from '../ts/index.js';
let testServer: typedserver.servertools.Server;
let testTypedRouter: typedrequest.TypedRouter;
let testTypedHandler: typedrequest.TypedHandler<ITestReqRes>;
// lets define an interface
@ -17,6 +18,16 @@ interface ITestReqRes {
};
}
interface ITestStream {
method: 'handleStream';
request: {
requestStream: any;
};
response: {
responseStream: any;
};
}
tap.test('should create a typedHandler', async () => {
// lets use the interface in a TypedHandler
testTypedHandler = new typedrequest.TypedHandler<ITestReqRes>('hi', async (reqArg) => {
@ -35,7 +46,7 @@ tap.test('should spawn a server to test with', async () => {
});
tap.test('should define a testHandler', async () => {
const testTypedRouter = new typedrequest.TypedRouter(); // typed routers can broker typedrequests between handlers
testTypedRouter = new typedrequest.TypedRouter(); // typed routers can broker typedrequests between handlers
testTypedRouter.addTypedHandler(testTypedHandler);
testServer.addRoute(
'/testroute',
@ -60,6 +71,24 @@ tap.test('should fire a request', async () => {
expect(response.surname).toEqual('wow');
});
tap.test('should allow VirtualStreams', async () => {
testTypedRouter.addTypedHandler(new typedrequest.TypedHandler<ITestStream>('handleStream', async (reqArg) => {
console.log('hey there');
console.log(reqArg.requestStream);
return {
responseStream: new typedrequest.VirtualStream(),
};
}));
const typedRequest = new typedrequest.TypedRequest<ITestStream>(
'http://localhost:3000/testroute',
'handleStream'
);
const response = await typedRequest.fire({
requestStream: new typedrequest.VirtualStream(),
});
console.log(response.responseStream);
})
tap.test('should end the server', async () => {
await testServer.stop();
});