Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e146b7741d | |||
| 02866cbe8d | |||
| 7a320d27a3 | |||
| 7910f9a856 | |||
| 05194609fe | |||
| eb0ec04199 | |||
| ffd5eb2e52 | |||
| c432079a70 | |||
| e2cab0bb59 | |||
| aaaa8b3ee4 | |||
| 4cc149069e | |||
| 6c106a4f22 | |||
| 85fca378ff | |||
| d096a08e42 | |||
| a715dd9e8c | |||
| ef8bf0a0d8 | |||
| f6d8910c45 | |||
| 0917b9dd06 | |||
| 0455c34cfa | |||
| a69fee7985 | |||
| 3e0d01520e | |||
| 7c4db19825 | |||
| f7205e2f29 | |||
| 0caf4becbe | |||
| 42af79a271 | |||
| 4dad23896c | |||
| 03ae15b10d | |||
| f66a5a80e1 | |||
| 4bd3c65588 | |||
| f29dd9bf1c | |||
| 2eeb4b7925 | |||
| 7e34275029 | |||
| c0e264146b | |||
| 951772d515 | |||
| d786a3b7cd | |||
| 6e0a48cc49 |
7628
package-lock.json
generated
7628
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
21
package.json
21
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@apiglobal/test-sdk",
|
"name": "@apiglobal/test-sdk",
|
||||||
"version": "1.0.7",
|
"version": "1.0.25",
|
||||||
"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,20 @@
|
|||||||
"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/qenv": "^4.0.10",
|
||||||
"@pushrocks/smartobject": "^1.0.3"
|
"@pushrocks/smartexpress": "^3.0.76",
|
||||||
|
"@pushrocks/smartobject": "^1.0.4"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
|
|||||||
33
ts/index.ts
33
ts/index.ts
@@ -1,13 +1,24 @@
|
|||||||
import * as plugins from './test-sdk.plugins';
|
import * as plugins from './test-sdk.plugins';
|
||||||
import { AgTestServer } from './test-sdk.classes.testserver';
|
import { AgTestServer } from './test-sdk.classes.testserver';
|
||||||
|
import { AAgHandler } from '@apiglobal/sdk';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
AgTestServer
|
AgTestServer
|
||||||
}
|
};
|
||||||
|
|
||||||
let testServer: AgTestServer;
|
let testServer: AgTestServer;
|
||||||
export const createTestServer = async (handlerArg: plugins.agSdk.AAgHandler<any>) => {
|
let handler: AAgHandler<any>;
|
||||||
testServer = new AgTestServer(handlerArg);
|
export const createTestServer = async (handlerArg: { new(envHandler: plugins.agSdk.AgEnvironment): plugins.agSdk.AAgHandler<any> }) => {
|
||||||
|
class AgEnvironement extends plugins.agSdk.AgEnvironment {
|
||||||
|
public qenv = new plugins.qenv.Qenv('./', './.nogit');
|
||||||
|
public async getEnvVar(nameArg: string) {
|
||||||
|
return this.qenv.getEnvVarOnDemand(nameArg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
handler = new handlerArg(new AgEnvironement());
|
||||||
|
console.log(`now checking requirements for handler with slug ${handler.slug}...`);
|
||||||
|
await handler.checkRequirements();
|
||||||
|
testServer = new AgTestServer(handler);
|
||||||
await testServer.start();
|
await testServer.start();
|
||||||
return testServer;
|
return testServer;
|
||||||
};
|
};
|
||||||
@@ -16,7 +27,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 +38,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 +49,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);
|
||||||
|
for (const divProperty of comparisonResult.divergingProperties) {
|
||||||
|
if (expectedResponseArg[divProperty] !== 'maydiverge') {
|
||||||
throwErrorBool = true;
|
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,12 +65,16 @@ 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 () => {
|
||||||
if (testServer) {
|
if (testServer) {
|
||||||
await testServer.stop();
|
await testServer.stop();
|
||||||
|
await handler.stop();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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);
|
||||||
|
console.log(`added handler with slug ${handlerArg.slug}`);
|
||||||
|
if (this.server && this.server.serverStatus === 'running') {
|
||||||
await this.stop();
|
await this.stop();
|
||||||
await this.start();
|
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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ import * as typedrequestInterfaces from '@apiglobal/typedrequest-interfaces';
|
|||||||
export { agSdk, typedrequest, typedrequestInterfaces };
|
export { agSdk, typedrequest, typedrequestInterfaces };
|
||||||
|
|
||||||
// pushrocks scope
|
// pushrocks scope
|
||||||
|
import * as qenv from '@pushrocks/qenv';
|
||||||
import * as smartexpress from '@pushrocks/smartexpress';
|
import * as smartexpress from '@pushrocks/smartexpress';
|
||||||
import * as smartobject from '@pushrocks/smartobject';
|
import * as smartobject from '@pushrocks/smartobject';
|
||||||
|
|
||||||
export { smartexpress, smartobject };
|
export { qenv, smartexpress, smartobject };
|
||||||
|
|||||||
Reference in New Issue
Block a user