30 Commits

Author SHA1 Message Date
ffd5eb2e52 1.0.22 2020-09-23 23:54:46 +00:00
c432079a70 fix(core): update 2020-09-23 23:54:46 +00:00
e2cab0bb59 1.0.21 2020-09-23 23:30:55 +00:00
aaaa8b3ee4 fix(core): update 2020-09-23 23:30:54 +00:00
4cc149069e 1.0.20 2020-07-28 17:24:53 +00:00
6c106a4f22 fix(core): update 2020-07-28 17:24:53 +00:00
85fca378ff 1.0.19 2020-07-28 17:14:17 +00:00
d096a08e42 fix(core): update 2020-07-28 17:14:16 +00:00
a715dd9e8c 1.0.18 2020-07-26 15:02:25 +00:00
ef8bf0a0d8 fix(core): update 2020-07-26 15:02:24 +00:00
f6d8910c45 1.0.17 2020-07-26 14:34:48 +00:00
0917b9dd06 fix(core): update 2020-07-26 14:34:47 +00:00
0455c34cfa 1.0.16 2020-07-26 14:01:17 +00:00
a69fee7985 fix(core): update 2020-07-26 14:01:17 +00:00
3e0d01520e 1.0.15 2020-07-26 13:54:47 +00:00
7c4db19825 fix(core): update 2020-07-26 13:54:46 +00:00
f7205e2f29 1.0.14 2020-07-25 16:58:07 +00:00
0caf4becbe fix(core): update 2020-07-25 16:58:06 +00:00
42af79a271 1.0.13 2020-07-25 16:34:11 +00:00
4dad23896c fix(core): update 2020-07-25 16:34:10 +00:00
03ae15b10d 1.0.12 2020-07-25 15:53:45 +00:00
f66a5a80e1 fix(core): update 2020-07-25 15:53:45 +00:00
4bd3c65588 1.0.11 2020-07-25 15:48:24 +00:00
f29dd9bf1c fix(core): update 2020-07-25 15:48:24 +00:00
2eeb4b7925 1.0.10 2020-07-25 15:47:35 +00:00
7e34275029 fix(core): update 2020-07-25 15:47:34 +00:00
c0e264146b 1.0.9 2020-07-25 15:40:11 +00:00
951772d515 fix(core): update 2020-07-25 15:40:10 +00:00
d786a3b7cd 1.0.8 2020-07-25 13:42:49 +00:00
6e0a48cc49 fix(core): update 2020-07-25 13:42:49 +00:00
4 changed files with 6871 additions and 794 deletions

7598
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{ {
"name": "@apiglobal/test-sdk", "name": "@apiglobal/test-sdk",
"version": "1.0.7", "version": "1.0.22",
"private": false, "private": false,
"description": "an sdk for testing ag handlers", "description": "an sdk for testing ag handlers",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
@@ -12,19 +12,19 @@
"build": "(tsbuild --web)" "build": "(tsbuild --web)"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.0.22", "@gitzone/tsbuild": "^2.1.25",
"@gitzone/tstest": "^1.0.15", "@gitzone/tstest": "^1.0.44",
"@pushrocks/tapbundle": "^3.0.7", "@pushrocks/tapbundle": "^3.2.9",
"@types/node": "^14.0.14", "@types/node": "^14.11.2",
"tslint": "^6.1.2", "tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0" "tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@apiglobal/sdk": "^1.0.9", "@apiglobal/sdk": "^1.0.13",
"@apiglobal/typedrequest": "^1.0.40", "@apiglobal/typedrequest": "^1.0.43",
"@apiglobal/typedrequest-interfaces": "^1.0.15", "@apiglobal/typedrequest-interfaces": "^1.0.15",
"@pushrocks/smartexpress": "^3.0.73", "@pushrocks/smartexpress": "^3.0.76",
"@pushrocks/smartobject": "^1.0.3" "@pushrocks/smartobject": "^1.0.4"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",

View File

@@ -3,11 +3,16 @@ import { AgTestServer } from './test-sdk.classes.testserver';
export { export {
AgTestServer AgTestServer
} };
let testServer: AgTestServer; let testServer: AgTestServer;
export const createTestServer = async (handlerArg: plugins.agSdk.AAgHandler<any>) => { export const createTestServer = async (handlerArg: { new(envHandler: plugins.agSdk.AgEnvironment): plugins.agSdk.AAgHandler<any> }) => {
testServer = new AgTestServer(handlerArg); class AgEnvironement extends plugins.agSdk.AgEnvironment {
public async getEnvVar(nameArg: string) {
return '';
}
}
testServer = new AgTestServer(new handlerArg(new AgEnvironement()));
await testServer.start(); await testServer.start();
return testServer; return testServer;
}; };
@@ -16,7 +21,7 @@ export const testFire = <
A extends plugins.agSdk.AAgHandler<any>, A extends plugins.agSdk.AAgHandler<any>,
T extends plugins.typedrequestInterfaces.ITypedRequest T extends plugins.typedrequestInterfaces.ITypedRequest
>( >(
slug: string, slugArg: A['slug'],
methodArg: T['method'], methodArg: T['method'],
requestArg: T['request'] requestArg: T['request']
) => { ) => {
@@ -27,7 +32,7 @@ export const testFire = <
throw new Error('you need to start the testServer first!'); throw new Error('you need to start the testServer first!');
} }
const typedRequest = new plugins.typedrequest.TypedRequest<T>( const typedRequest = new plugins.typedrequest.TypedRequest<T>(
`https://localhost:${testServer.server.options.port}`, `http://localhost:${testServer.server.options.port}/${slugArg}`,
methodArg methodArg
); );
const responsePromise = typedRequest.fire(requestArg); const responsePromise = typedRequest.fire(requestArg);
@@ -38,7 +43,13 @@ export const testFire = <
if (comparisonResult.divergingProperties.length > 0) { if (comparisonResult.divergingProperties.length > 0) {
console.log(`The following properties diverged:`); console.log(`The following properties diverged:`);
console.log(comparisonResult.divergingProperties); console.log(comparisonResult.divergingProperties);
throwErrorBool = true; for (const divProperty of comparisonResult.divergingProperties) {
if (expectedResponseArg[divProperty] !== 'maydiverge') {
throwErrorBool = true;
} else {
console.log(`${divProperty} may diverge, not throwing for this one`);
}
}
} }
if (comparisonResult.missingProperties.length > 0) { if (comparisonResult.missingProperties.length > 0) {
console.log(`The following properties diverged:`); console.log(`The following properties diverged:`);
@@ -48,8 +59,11 @@ export const testFire = <
if (throwErrorBool) { if (throwErrorBool) {
throw new Error('response did not comply'); throw new Error('response did not comply');
} }
return actualResponse;
};
return {
expect
}; };
return expect;
}; };
export const stopTestServer = async () => { export const stopTestServer = async () => {

View File

@@ -6,28 +6,37 @@ export class AgTestServer {
constructor(handlerArg?: plugins.agSdk.AAgHandler<any>) { constructor(handlerArg?: plugins.agSdk.AAgHandler<any>) {
if (handlerArg) { if (handlerArg) {
this.handlers.push(handlerArg); this.addAgHandler(handlerArg);
} }
} }
public async addAgHandler(handlerArg: plugins.agSdk.AAgHandler<any>) { public async addAgHandler(handlerArg: plugins.agSdk.AAgHandler<any>) {
this.handlers.push(handlerArg); this.handlers.push(handlerArg);
await this.stop(); console.log(`added handler with slug ${handlerArg.slug}`);
await this.start(); if (this.server && this.server.serverStatus === 'running') {
await this.stop();
await this.start();
}
} }
public async start() { public async start() {
this.server = new plugins.smartexpress.Server({ this.server = new plugins.smartexpress.Server({
cors: true, cors: true,
forceSsl: false,
defaultAnswer: async () => 'apiglobal testserver', defaultAnswer: async () => 'apiglobal testserver',
domain: 'localhost', domain: 'localhost',
forceSsl: false, port: 3000,
}); });
for (const handlerArg of this.handlers) { 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( this.server.addRoute(
`/${handlerArg.slug}`, slugroute,
new plugins.smartexpress.HandlerTypedRouter(handlerArg.typedrouter) new plugins.smartexpress.HandlerTypedRouter(handlerArg.typedrouter)
); );
console.log(`added slugroute ${slugroute}`);
} }
await this.server.start(); await this.server.start();
} }