48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { expect, tap } from '@push.rocks/tapbundle';
|
|
|
|
import * as typedrequest from '../ts/index.js';
|
|
|
|
let testTypedHandler: typedrequest.TypedHandler<ITestReqRes>;
|
|
|
|
// lets define an interface
|
|
interface ITestReqRes {
|
|
method: 'hi';
|
|
request: {
|
|
name: string;
|
|
};
|
|
response: {
|
|
surname: string;
|
|
};
|
|
}
|
|
|
|
tap.test('should create a typedHandler', async () => {
|
|
// lets use the interface in a TypedHandler
|
|
testTypedHandler = new typedrequest.TypedHandler<ITestReqRes>('hi', async (reqArg) => {
|
|
return {
|
|
surname: 'wow',
|
|
};
|
|
});
|
|
});
|
|
|
|
tap.test('should define a testHandler', async () => {
|
|
const testTypedRouter = new typedrequest.TypedRouter(); // typed routers can broker typedrequests between handlers
|
|
testTypedRouter.addTypedHandler(testTypedHandler);
|
|
});
|
|
|
|
tap.skip.test('should fire a request', async () => {
|
|
let response = await fetch('http://localhost:3000/typedrequest', {
|
|
"method": "POST",
|
|
"headers": {
|
|
"Content-Type": "application/json"
|
|
},
|
|
"body": "{\"correlation\":{\"id\":\"uni_aefe56c1a0f61a3e91082209\",\"phase\":\"request\"},\"method\":\"hi\",\"request\":{\"name\":\"yes\"},\"response\":null}"
|
|
})
|
|
console.log(await response.text());
|
|
});
|
|
|
|
tap.skip.test('test', async (tools) => {
|
|
await tools.delayFor(5000);
|
|
})
|
|
|
|
export default tap.start();
|