fix(core): update

This commit is contained in:
2020-07-25 13:34:26 +00:00
parent 6df4f8de77
commit 6ec6869e9c
4 changed files with 115 additions and 19 deletions

View File

@ -1,7 +1,9 @@
import * as plugins from './test-sdk.plugins';
import { AgTestServer } from './test-sdk.classes.testserver';
export { AgTestServer };
export {
AgTestServer
}
let testServer: AgTestServer;
export const createTestServer = async (handlerArg: plugins.agSdk.AAgHandler<any>) => {
@ -10,6 +12,46 @@ export const createTestServer = async (handlerArg: plugins.agSdk.AAgHandler<any>
return testServer;
};
export const testFire = <
A extends plugins.agSdk.AAgHandler<any>,
T extends plugins.typedrequestInterfaces.ITypedRequest
>(
slug: string,
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>(
`https://localhost:${testServer.server.options.port}`,
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();

View File

@ -1,9 +1,12 @@
// apiglobal scope
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
import * as smartexpress from '@pushrocks/smartexpress';
import * as smartobject from '@pushrocks/smartobject';
export { smartexpress };
export { smartexpress, smartobject };