fix(core): update

This commit is contained in:
2024-02-25 01:54:01 +01:00
parent 51fedb270b
commit b346da01f1
6 changed files with 78 additions and 39 deletions

View File

@ -2,6 +2,7 @@ import { expect, tap } from '@push.rocks/tapbundle';
import * as typedserver from '@api.global/typedserver';
import * as typedrequest from '../ts/index.js';
import * as typedrequestInterfaces from '@api.global/typedrequest-interfaces';
let testServer: typedserver.servertools.Server;
let testTypedRouter: typedrequest.TypedRouter;
@ -21,10 +22,10 @@ interface ITestReqRes {
interface ITestStream {
method: 'handleStream';
request: {
requestStream: any;
requestStream: typedrequestInterfaces.IVirtualStream;
};
response: {
responseStream: any;
responseStream: typedrequestInterfaces.IVirtualStream;
};
}
@ -72,11 +73,16 @@ tap.test('should fire a request', async () => {
});
tap.test('should allow VirtualStreams', async () => {
const newRequestingVS = new typedrequest.VirtualStream();
const newRespondingVS = new typedrequest.VirtualStream();
let generatedRequestingVS: typedrequestInterfaces.IVirtualStream;
let generatedRespondingVS: typedrequestInterfaces.IVirtualStream;
testTypedRouter.addTypedHandler(new typedrequest.TypedHandler<ITestStream>('handleStream', async (reqArg) => {
console.log('hey there');
console.log(reqArg.requestStream);
generatedRequestingVS = reqArg.requestStream;
return {
responseStream: new typedrequest.VirtualStream(),
responseStream: newRespondingVS,
};
}));
const typedRequest = new typedrequest.TypedRequest<ITestStream>(
@ -84,9 +90,14 @@ tap.test('should allow VirtualStreams', async () => {
'handleStream'
);
const response = await typedRequest.fire({
requestStream: new typedrequest.VirtualStream(),
requestStream: newRequestingVS,
});
console.log(response.responseStream);
newRequestingVS.sendData(Buffer.from('hello'));
const data = await generatedRequestingVS.fetchData();
const decodedData = data.toString();
expect(data.toString()).toEqual('hello');
})
tap.test('should end the server', async (toolsArg) => {