typedrequest/test/test.browser.ts

48 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-08-04 14:10:47 +00:00
import { expect, tap } from '@push.rocks/tapbundle';
2020-10-09 10:25:28 +00:00
2022-03-24 19:02:58 +00:00
import * as typedrequest from '../ts/index.js';
2020-10-09 10:25:28 +00:00
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);
});
2024-03-03 09:42:14 +00:00
tap.skip.test('should fire a request', async () => {
2024-02-29 23:26:06 +00:00
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}"
2024-02-29 23:12:43 +00:00
})
2024-02-29 23:26:06 +00:00
console.log(await response.text());
2020-10-09 10:25:28 +00:00
});
2024-03-03 09:42:14 +00:00
tap.skip.test('test', async (tools) => {
2024-02-29 23:12:43 +00:00
await tools.delayFor(5000);
})
2020-10-09 10:25:28 +00:00
tap.start();