16 Commits

Author SHA1 Message Date
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
88c0fc101b 1.0.7 2020-07-25 13:34:27 +00:00
6ec6869e9c fix(core): update 2020-07-25 13:34:26 +00:00
5 changed files with 6097 additions and 180 deletions

6209
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.6", "version": "1.0.14",
"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",
@@ -13,15 +13,18 @@
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.0.22", "@gitzone/tsbuild": "^2.0.22",
"@gitzone/tstest": "^1.0.15", "@gitzone/tstest": "^1.0.43",
"@pushrocks/tapbundle": "^3.0.7", "@pushrocks/tapbundle": "^3.2.9",
"@types/node": "^14.0.14", "@types/node": "^14.0.26",
"tslint": "^6.1.2", "tslint": "^6.1.2",
"tslint-config-prettier": "^1.18.0" "tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@apiglobal/sdk": "^1.0.9", "@apiglobal/sdk": "^1.0.9",
"@pushrocks/smartexpress": "^3.0.73" "@apiglobal/typedrequest": "^1.0.40",
"@apiglobal/typedrequest-interfaces": "^1.0.15",
"@pushrocks/smartexpress": "^3.0.73",
"@pushrocks/smartobject": "^1.0.4"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",

View File

@@ -1,7 +1,9 @@
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';
export { AgTestServer }; export {
AgTestServer
};
let testServer: AgTestServer; let testServer: AgTestServer;
export const createTestServer = async (handlerArg: plugins.agSdk.AAgHandler<any>) => { export const createTestServer = async (handlerArg: plugins.agSdk.AAgHandler<any>) => {
@@ -10,6 +12,48 @@ export const createTestServer = async (handlerArg: plugins.agSdk.AAgHandler<any>
return testServer; return testServer;
}; };
export const testFire = <
A extends plugins.agSdk.AAgHandler<any>,
T extends plugins.typedrequestInterfaces.ITypedRequest
>(
slugArg: A['slug'],
methodArg: T['method'],
requestArg: T['request']
) => {
if (!testServer) {
throw new Error('you need to create and start a testServer first!');
}
if (testServer.server.serverStatus !== 'running') {
throw new Error('you need to start the testServer first!');
}
const typedRequest = new plugins.typedrequest.TypedRequest<T>(
`http://localhost:${testServer.server.options.port}/${slugArg}`,
methodArg
);
const responsePromise = typedRequest.fire(requestArg);
const expect = async (expectedResponseArg: T['response']) => {
const actualResponse = await responsePromise;
const comparisonResult = plugins.smartobject.compareObjects(expectedResponseArg, actualResponse);
let throwErrorBool = false;
if (comparisonResult.divergingProperties.length > 0) {
console.log(`The following properties diverged:`);
console.log(comparisonResult.divergingProperties);
throwErrorBool = true;
}
if (comparisonResult.missingProperties.length > 0) {
console.log(`The following properties diverged:`);
console.log(comparisonResult.divergingProperties);
throwErrorBool = true;
}
if (throwErrorBool) {
throw new Error('response did not comply');
}
};
return {
expect
};
};
export const stopTestServer = async () => { export const stopTestServer = async () => {
if (testServer) { if (testServer) {
await testServer.stop(); await testServer.stop();

View File

@@ -21,9 +21,11 @@ export class AgTestServer {
cors: true, cors: true,
defaultAnswer: async () => 'apiglobal testserver', defaultAnswer: async () => 'apiglobal testserver',
domain: 'localhost', domain: 'localhost',
port: 3000,
forceSsl: false, forceSsl: false,
}); });
for (const handlerArg of this.handlers) { for (const handlerArg of this.handlers) {
await handlerArg.start();
this.server.addRoute( this.server.addRoute(
`/${handlerArg.slug}`, `/${handlerArg.slug}`,
new plugins.smartexpress.HandlerTypedRouter(handlerArg.typedrouter) new plugins.smartexpress.HandlerTypedRouter(handlerArg.typedrouter)

View File

@@ -1,9 +1,12 @@
// apiglobal scope // apiglobal scope
import * as agSdk from '@apiglobal/sdk'; import * as agSdk from '@apiglobal/sdk';
import * as typedrequest from '@apiglobal/typedrequest';
import * as typedrequestInterfaces from '@apiglobal/typedrequest-interfaces';
export { agSdk }; export { agSdk, typedrequest, typedrequestInterfaces };
// pushrocks scope // pushrocks scope
import * as smartexpress from '@pushrocks/smartexpress'; import * as smartexpress from '@pushrocks/smartexpress';
import * as smartobject from '@pushrocks/smartobject';
export { smartexpress }; export { smartexpress, smartobject };