Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0455c34cfa | |||
| a69fee7985 | |||
| 3e0d01520e | |||
| 7c4db19825 | |||
| f7205e2f29 | |||
| 0caf4becbe | |||
| 42af79a271 | |||
| 4dad23896c | |||
| 03ae15b10d | |||
| f66a5a80e1 | |||
| 4bd3c65588 | |||
| f29dd9bf1c | |||
| 2eeb4b7925 | |||
| 7e34275029 | |||
| c0e264146b | |||
| 951772d515 | |||
| d786a3b7cd | |||
| 6e0a48cc49 | |||
| 88c0fc101b | |||
| 6ec6869e9c | |||
| 6df4f8de77 | |||
| 29f4529dd8 | |||
| a2392644b1 | |||
| 4a8c3159c0 | |||
| b118e03520 | |||
| 7675c27cab | |||
| 4251dbf0af | |||
| 6e42d063c5 |
6779
package-lock.json
generated
6779
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
25
package.json
25
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@apiglobal/test-sdk",
|
"name": "@apiglobal/test-sdk",
|
||||||
"version": "1.0.2",
|
"version": "1.0.16",
|
||||||
"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",
|
||||||
@@ -8,19 +8,24 @@
|
|||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/ --web)",
|
||||||
"build": "(tsbuild)",
|
"build": "(tsbuild --web)"
|
||||||
"format": "(gitzone format)"
|
|
||||||
},
|
},
|
||||||
"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": "^10.11.7",
|
"@types/node": "^14.0.26",
|
||||||
"tslint": "^5.11.0",
|
"tslint": "^6.1.2",
|
||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@apiglobal/sdk": "^1.0.9",
|
||||||
|
"@apiglobal/typedrequest": "^1.0.40",
|
||||||
|
"@apiglobal/typedrequest-interfaces": "^1.0.15",
|
||||||
|
"@pushrocks/smartexpress": "^3.0.73",
|
||||||
|
"@pushrocks/smartobject": "^1.0.4"
|
||||||
},
|
},
|
||||||
"dependencies": {},
|
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
"ts_web/**/*",
|
"ts_web/**/*",
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import * as testSdk from '../ts/index';
|
import * as testSdk from '../ts/index';
|
||||||
|
|
||||||
|
let testServer: testSdk.AgTestServer;
|
||||||
|
|
||||||
tap.test('first test', async () => {
|
tap.test('first test', async () => {
|
||||||
console.log(testSdk.standardExport);
|
console.log('TODO');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
|||||||
60
ts/index.ts
60
ts/index.ts
@@ -1,3 +1,61 @@
|
|||||||
import * as plugins from './test-sdk.plugins';
|
import * as plugins from './test-sdk.plugins';
|
||||||
|
import { AgTestServer } from './test-sdk.classes.testserver';
|
||||||
|
|
||||||
export let standardExport = 'Hi there! :) This is an exported string';
|
export {
|
||||||
|
AgTestServer
|
||||||
|
};
|
||||||
|
|
||||||
|
let testServer: AgTestServer;
|
||||||
|
export const createTestServer = async (handlerArg: plugins.agSdk.AAgHandler<any>) => {
|
||||||
|
testServer = new AgTestServer(handlerArg);
|
||||||
|
await testServer.start();
|
||||||
|
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 () => {
|
||||||
|
if (testServer) {
|
||||||
|
await testServer.stop();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
52
ts/test-sdk.classes.testserver.ts
Normal file
52
ts/test-sdk.classes.testserver.ts
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import * as plugins from './test-sdk.plugins';
|
||||||
|
|
||||||
|
export class AgTestServer {
|
||||||
|
public handlers: Array<plugins.agSdk.AAgHandler<any>> = [];
|
||||||
|
public server: plugins.smartexpress.Server;
|
||||||
|
|
||||||
|
constructor(handlerArg?: plugins.agSdk.AAgHandler<any>) {
|
||||||
|
if (handlerArg) {
|
||||||
|
this.addAgHandler(handlerArg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async addAgHandler(handlerArg: plugins.agSdk.AAgHandler<any>) {
|
||||||
|
this.handlers.push(handlerArg);
|
||||||
|
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',
|
||||||
|
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(
|
||||||
|
slugroute,
|
||||||
|
new plugins.smartexpress.HandlerTypedRouter(handlerArg.typedrouter)
|
||||||
|
);
|
||||||
|
console.log(`added slugroute ${slugroute}`);
|
||||||
|
}
|
||||||
|
await this.server.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async stop() {
|
||||||
|
if (this.server) {
|
||||||
|
const previousServer = this.server;
|
||||||
|
this.server = null;
|
||||||
|
await previousServer.startedPromise;
|
||||||
|
await previousServer.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,2 +1,12 @@
|
|||||||
const removeme = {};
|
// apiglobal scope
|
||||||
export { removeme };
|
import * as agSdk from '@apiglobal/sdk';
|
||||||
|
import * as typedrequest from '@apiglobal/typedrequest';
|
||||||
|
import * as typedrequestInterfaces from '@apiglobal/typedrequest-interfaces';
|
||||||
|
|
||||||
|
export { agSdk, typedrequest, typedrequestInterfaces };
|
||||||
|
|
||||||
|
// pushrocks scope
|
||||||
|
import * as smartexpress from '@pushrocks/smartexpress';
|
||||||
|
import * as smartobject from '@pushrocks/smartobject';
|
||||||
|
|
||||||
|
export { smartexpress, smartobject };
|
||||||
|
|||||||
Reference in New Issue
Block a user