Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0455c34cfa | |||
| a69fee7985 | |||
| 3e0d01520e | |||
| 7c4db19825 | |||
| f7205e2f29 | |||
| 0caf4becbe | |||
| 42af79a271 | |||
| 4dad23896c | |||
| 03ae15b10d | |||
| f66a5a80e1 | |||
| 4bd3c65588 | |||
| f29dd9bf1c | |||
| 2eeb4b7925 | |||
| 7e34275029 | |||
| c0e264146b | |||
| 951772d515 |
6137
package-lock.json
generated
6137
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@apiglobal/test-sdk",
|
||||
"version": "1.0.8",
|
||||
"version": "1.0.16",
|
||||
"private": false,
|
||||
"description": "an sdk for testing ag handlers",
|
||||
"main": "dist_ts/index.js",
|
||||
@@ -13,9 +13,9 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.0.22",
|
||||
"@gitzone/tstest": "^1.0.15",
|
||||
"@pushrocks/tapbundle": "^3.0.7",
|
||||
"@types/node": "^14.0.14",
|
||||
"@gitzone/tstest": "^1.0.43",
|
||||
"@pushrocks/tapbundle": "^3.2.9",
|
||||
"@types/node": "^14.0.26",
|
||||
"tslint": "^6.1.2",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
@@ -24,7 +24,7 @@
|
||||
"@apiglobal/typedrequest": "^1.0.40",
|
||||
"@apiglobal/typedrequest-interfaces": "^1.0.15",
|
||||
"@pushrocks/smartexpress": "^3.0.73",
|
||||
"@pushrocks/smartobject": "^1.0.3"
|
||||
"@pushrocks/smartobject": "^1.0.4"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
|
||||
10
ts/index.ts
10
ts/index.ts
@@ -3,7 +3,7 @@ import { AgTestServer } from './test-sdk.classes.testserver';
|
||||
|
||||
export {
|
||||
AgTestServer
|
||||
}
|
||||
};
|
||||
|
||||
let testServer: AgTestServer;
|
||||
export const createTestServer = async (handlerArg: plugins.agSdk.AAgHandler<any>) => {
|
||||
@@ -16,7 +16,7 @@ export const testFire = <
|
||||
A extends plugins.agSdk.AAgHandler<any>,
|
||||
T extends plugins.typedrequestInterfaces.ITypedRequest
|
||||
>(
|
||||
slug: A['slug'],
|
||||
slugArg: A['slug'],
|
||||
methodArg: T['method'],
|
||||
requestArg: T['request']
|
||||
) => {
|
||||
@@ -27,7 +27,7 @@ export const testFire = <
|
||||
throw new Error('you need to start the testServer first!');
|
||||
}
|
||||
const typedRequest = new plugins.typedrequest.TypedRequest<T>(
|
||||
`https://localhost:${testServer.server.options.port}`,
|
||||
`http://localhost:${testServer.server.options.port}/${slugArg}`,
|
||||
methodArg
|
||||
);
|
||||
const responsePromise = typedRequest.fire(requestArg);
|
||||
@@ -49,7 +49,9 @@ export const testFire = <
|
||||
throw new Error('response did not comply');
|
||||
}
|
||||
};
|
||||
return expect;
|
||||
return {
|
||||
expect
|
||||
};
|
||||
};
|
||||
|
||||
export const stopTestServer = async () => {
|
||||
|
||||
@@ -6,28 +6,37 @@ export class AgTestServer {
|
||||
|
||||
constructor(handlerArg?: plugins.agSdk.AAgHandler<any>) {
|
||||
if (handlerArg) {
|
||||
this.handlers.push(handlerArg);
|
||||
this.addAgHandler(handlerArg);
|
||||
}
|
||||
}
|
||||
|
||||
public async addAgHandler(handlerArg: plugins.agSdk.AAgHandler<any>) {
|
||||
this.handlers.push(handlerArg);
|
||||
await this.stop();
|
||||
await this.start();
|
||||
console.log(`added handler with slug ${handlerArg.slug}`);
|
||||
if (this.server && this.server.serverStatus === 'running') {
|
||||
await this.stop();
|
||||
await this.start();
|
||||
}
|
||||
}
|
||||
|
||||
public async start() {
|
||||
this.server = new plugins.smartexpress.Server({
|
||||
cors: true,
|
||||
forceSsl: false,
|
||||
defaultAnswer: async () => 'apiglobal testserver',
|
||||
domain: 'localhost',
|
||||
forceSsl: false,
|
||||
port: 3000,
|
||||
});
|
||||
for (const handlerArg of this.handlers) {
|
||||
console.log(`found handler with slug ${handlerArg.slug}`);
|
||||
await handlerArg.start();
|
||||
console.log(`started handler with slug ${handlerArg.slug}`);
|
||||
const slugroute = `/${handlerArg.slug}`;
|
||||
this.server.addRoute(
|
||||
`/${handlerArg.slug}`,
|
||||
slugroute,
|
||||
new plugins.smartexpress.HandlerTypedRouter(handlerArg.typedrouter)
|
||||
);
|
||||
console.log(`added slugroute ${slugroute}`);
|
||||
}
|
||||
await this.server.start();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user