fix(core): update
This commit is contained in:
44
ts/index.ts
44
ts/index.ts
@ -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();
|
||||
|
@ -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 };
|
||||
|
Reference in New Issue
Block a user