diff --git a/package-lock.json b/package-lock.json index 90e0e23..802dc1d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,20 +14,64 @@ } }, "@apiglobal/typedrequest": { - "version": "1.0.38", - "resolved": "https://verdaccio.lossless.one/@apiglobal%2ftypedrequest/-/typedrequest-1.0.38.tgz", - "integrity": "sha512-A0kFQJEadwOc9Zlnc4QvVoqL0e5zaEGye+dUDlfq3p9jvis6KbDSamG+xcGXw1HTz7BxFp66Ix73qwHUzWkHeg==", + "version": "1.0.40", + "resolved": "https://verdaccio.lossless.one/@apiglobal%2ftypedrequest/-/typedrequest-1.0.40.tgz", + "integrity": "sha512-CnYa7h6rZWe3GPf0h8F8M/LNQ1wpGRvtFnx5R6h8ukIT3agXyJIWaCpR4k8yAokSvUov4ZVwadH/FGNS1fHrfw==", "requires": { - "@apiglobal/typedrequest-interfaces": "^1.0.13", - "@pushrocks/lik": "^4.0.13", - "@pushrocks/smartdelay": "^2.0.9", - "@pushrocks/webrequest": "^2.0.9" + "@apiglobal/typedrequest-interfaces": "^1.0.15", + "@pushrocks/isounique": "^1.0.4", + "@pushrocks/lik": "^4.0.17", + "@pushrocks/smartdelay": "^2.0.10", + "@pushrocks/smartpromise": "^3.0.6", + "@pushrocks/webrequest": "^2.0.10" + }, + "dependencies": { + "@apiglobal/typedrequest-interfaces": { + "version": "1.0.15", + "resolved": "https://verdaccio.lossless.one/@apiglobal%2ftypedrequest-interfaces/-/typedrequest-interfaces-1.0.15.tgz", + "integrity": "sha512-KncX168fUQJ73FeT22Cvls41mkJmtasP8dB2s9+9/OyWZpNsCzk9NEmtdRhulW2vLQwuAbQc1eoloe7ffCmhcA==" + }, + "@pushrocks/lik": { + "version": "4.0.17", + "resolved": "https://verdaccio.lossless.one/@pushrocks%2flik/-/lik-4.0.17.tgz", + "integrity": "sha512-K5dX3k3i7iVxFMJ+IYwJRljewukJCc2zgj6+88R18/8SajVAq7ITOl3/FTbmEPFCJv5rl/LQ9FtcMynWlwSlzQ==", + "requires": { + "@pushrocks/smartdelay": "^2.0.10", + "@pushrocks/smartmatch": "^1.0.7", + "@pushrocks/smartpromise": "^3.0.6", + "@pushrocks/smartrx": "^2.0.17", + "@pushrocks/smarttime": "^3.0.24", + "@types/minimatch": "^3.0.3", + "symbol-tree": "^3.2.4" + } + }, + "@pushrocks/smartdelay": { + "version": "2.0.10", + "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartdelay/-/smartdelay-2.0.10.tgz", + "integrity": "sha512-JOFpEfYiKnqcQYoUrL/jDyBDZUmlgJNm5U30MQQ3f+yci+rlFnMY5VvBBEYn5WgoX0ilwU+E15mtpDWhXcmhzg==", + "requires": { + "@pushrocks/smartpromise": "^3.0.6" + } + }, + "@pushrocks/smarttime": { + "version": "3.0.24", + "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmarttime/-/smarttime-3.0.24.tgz", + "integrity": "sha512-c/n0Y3CUnVNa3TnuXZ5aRc0bWj4RX7+XSjPes1J4HidU1yBOd9UOt6l08W8aPH5jMjT9Ei2jH0GsheaTGoVEYA==", + "requires": { + "@pushrocks/lik": "^4.0.13", + "@pushrocks/smartdelay": "^2.0.10", + "@pushrocks/smartpromise": "^3.0.2", + "croner": "^1.1.23", + "dayjs": "^1.8.29", + "is-nan": "^1.3.0" + } + } } }, "@apiglobal/typedrequest-interfaces": { - "version": "1.0.13", - "resolved": "https://verdaccio.lossless.one/@apiglobal%2ftypedrequest-interfaces/-/typedrequest-interfaces-1.0.13.tgz", - "integrity": "sha512-3mk0mMC7unqh+Bb0mPEMwEfJcLAGl5ZjA1If/OGyk56KQOBqA2mLATS40HREeGoAEcUOHU2VCwPuU/tpSVMY/w==" + "version": "1.0.15", + "resolved": "https://verdaccio.lossless.one/@apiglobal%2ftypedrequest-interfaces/-/typedrequest-interfaces-1.0.15.tgz", + "integrity": "sha512-KncX168fUQJ73FeT22Cvls41mkJmtasP8dB2s9+9/OyWZpNsCzk9NEmtdRhulW2vLQwuAbQc1eoloe7ffCmhcA==" }, "@babel/code-frame": { "version": "7.10.4", @@ -1142,8 +1186,7 @@ "@pushrocks/isounique": { "version": "1.0.4", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fisounique/-/isounique-1.0.4.tgz", - "integrity": "sha512-P1xLsuA1+8LQpoWCo2nP2vIQXKGUl5wDWU6CD7xTDZc3uw0He5V/qCPHM5zpIZsS7IuZOxDDpWb7aFveB11tXw==", - "dev": true + "integrity": "sha512-P1xLsuA1+8LQpoWCo2nP2vIQXKGUl5wDWU6CD7xTDZc3uw0He5V/qCPHM5zpIZsS7IuZOxDDpWb7aFveB11tXw==" }, "@pushrocks/lik": { "version": "4.0.13", @@ -1380,6 +1423,11 @@ "systeminformation": "^4.15.3" } }, + "@pushrocks/smartobject": { + "version": "1.0.3", + "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartobject/-/smartobject-1.0.3.tgz", + "integrity": "sha512-zByvI2HHCumnoRYEWCYoDZqm9k3t/qeVo/LjmbZsdy8wVS/20Dveirexk52jEELFT3cr8IX88FvVZQ6b3pPUzQ==" + }, "@pushrocks/smartparam": { "version": "1.1.6", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartparam/-/smartparam-1.1.6.tgz", @@ -1523,9 +1571,9 @@ } }, "@pushrocks/webrequest": { - "version": "2.0.9", - "resolved": "https://verdaccio.lossless.one/@pushrocks%2fwebrequest/-/webrequest-2.0.9.tgz", - "integrity": "sha512-cHKbVlS6j26SRzFMjvV+4hwwimXJ9NX/NnUmLmPSTZguzz6dEp1dYd+aNzGaGC8Da4ewvH7klhx7a5LI3Gv5tw==", + "version": "2.0.10", + "resolved": "https://verdaccio.lossless.one/@pushrocks%2fwebrequest/-/webrequest-2.0.10.tgz", + "integrity": "sha512-uQ8MvKclGqdLaUjah3SUsr8RplvtEUDXpFYjyO1dsHabbLWNVPQipt70CAMvS/8hOzDDD/G+dUEHIz2yZSVKNQ==", "requires": { "@pushrocks/smartdelay": "^2.0.9", "@pushrocks/smartenv": "^4.0.10", diff --git a/package.json b/package.json index 487184a..16d6dbc 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,10 @@ }, "dependencies": { "@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.3" }, "files": [ "ts/**/*", diff --git a/ts/index.ts b/ts/index.ts index e8e0c0c..e5551a4 100644 --- a/ts/index.ts +++ b/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) => { @@ -10,6 +12,46 @@ export const createTestServer = async (handlerArg: plugins.agSdk.AAgHandler return testServer; }; +export const testFire = < + A extends plugins.agSdk.AAgHandler, + 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( + `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(); diff --git a/ts/test-sdk.plugins.ts b/ts/test-sdk.plugins.ts index 97ec8a2..0ed3462 100644 --- a/ts/test-sdk.plugins.ts +++ b/ts/test-sdk.plugins.ts @@ -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 };