Compare commits

...

11 Commits

Author SHA1 Message Date
25a9bb4ec8 1.0.26 2019-09-01 15:39:57 +02:00
2796498984 fix(core): update 2019-09-01 15:39:56 +02:00
68e16e80f0 1.0.25 2019-09-01 15:39:08 +02:00
d1aa752c8e fix(core): update 2019-09-01 15:39:08 +02:00
e7d8731fca 1.0.24 2019-09-01 14:14:29 +02:00
7c3c7ca90e 1.0.23 2019-09-01 13:17:21 +02:00
db474ebd8a fix(core): update 2019-09-01 13:17:21 +02:00
51219303a9 1.0.22 2019-08-31 23:15:05 +02:00
ccc9303c63 fix(core): update 2019-08-31 23:15:05 +02:00
69b7147ae7 1.0.21 2019-08-31 23:14:47 +02:00
3667946b2f fix(core): update 2019-08-31 23:14:46 +02:00
5 changed files with 1240 additions and 6 deletions

1175
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@apiglobal/typedrequest",
"version": "1.0.20",
"version": "1.0.26",
"private": false,
"description": "make typed requests towards apis",
"main": "dist/index.js",
@ -15,6 +15,7 @@
"devDependencies": {
"@gitzone/tsbuild": "^2.0.22",
"@gitzone/tstest": "^1.0.15",
"@pushrocks/smartexpress": "^3.0.40",
"@pushrocks/tapbundle": "^3.0.13",
"@types/node": "^12.7.2",
"tslint": "^5.19.0",

View File

@ -1,8 +1,59 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as smartexpress from '@pushrocks/smartexpress';
import * as typedrequest from '../ts/index';
tap.test('first test', async () => {
typedrequest.TypedRequest;
let testServer: smartexpress.Server;
let testTypedHandler: typedrequest.TypedHandler<ITestReqRes>;
interface ITestReqRes {
method: 'hi';
request: {
name: string;
};
response: {
surname: string;
};
}
tap.test('should create a typedHandler', async () => {
testTypedHandler = new typedrequest.TypedHandler<ITestReqRes>('hi', async (reqArg) => {
return {
surname: 'wow'
};
});
});
tap.test('should spawn a server to test with', async () => {
testServer = new smartexpress.Server({
cors: true,
forceSsl: false,
port: 3000
});
});
tap.test('should define a testHandler', async () => {
testServer.addRoute('/testroute', new smartexpress.Handler('POST', async (req, res) => {
console.log(req.body);
res.json(await testTypedHandler.addResponse(req.body));
}));
});
tap.test('should start the server', async () => {
await testServer.start();
});
tap.test('should fire a request', async () => {
const typedRequest = new typedrequest.TypedRequest<ITestReqRes>('http://localhost:3000/testroute', 'hi');
const response = await typedRequest.fire({
name: 'really'
});
console.log(response);
expect(response.surname).to.equal('wow');
});
tap.test('should end the server', async () => {
await testServer.stop();
});
tap.start();

View File

@ -14,14 +14,18 @@ export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest
* firest the request
*/
public async fire(fireArg: T['request']): Promise<T['response']> {
const response = await plugins.smartrequest.request(this.urlEndPoint, {
method: 'POST',
const response = await plugins.smartrequest.postJson(this.urlEndPoint, {
requestBody: {
method: this.method,
request: fireArg,
response: null
}
});
const responseBody: T = response.body;
if (responseBody.error) {
console.log(responseBody.error.text);
console.log(responseBody.error.data);
}
return response.body.response;
}
}

View File

@ -33,6 +33,11 @@ export class TypedRouter {
console.log(`Cannot find method for ${typedHandler}`);
console.log(`Available methods are:`);
console.log(availableMethods);
typedRequest.error = {
text: 'There is no available method for this call on the server side',
data: {}
};
return typedRequest;
}
typedRequest = await typedHandler.addResponse(typedRequest);