Compare commits

...

19 Commits

Author SHA1 Message Date
5ea494cef3 update documentation 2024-04-14 18:57:25 +02:00
1830daacba 2.0.2 2023-03-20 14:47:10 +01:00
52cca1c8f3 fix(core): update 2023-03-20 14:47:09 +01:00
fd5f50e420 2.0.1 2023-03-20 14:36:27 +01:00
ce88b62d3c fix(core): update 2023-03-20 14:36:27 +01:00
9fa3165304 2.0.0 2023-03-20 14:23:33 +01:00
069d61ccf7 BREAKING CHANGE(core): update 2023-03-20 14:23:33 +01:00
0b56464a5f 1.0.27 2020-10-20 20:31:28 +00:00
4805687305 fix(core): update 2020-10-20 20:31:28 +00:00
c387a633bb 1.0.26 2020-10-20 20:28:34 +00:00
99efc2d5fe fix(core): update 2020-10-20 20:28:33 +00:00
e146b7741d 1.0.25 2020-09-24 00:59:02 +00:00
02866cbe8d fix(core): update 2020-09-24 00:59:01 +00:00
7a320d27a3 1.0.24 2020-09-24 00:45:24 +00:00
7910f9a856 fix(core): update 2020-09-24 00:45:23 +00:00
05194609fe 1.0.23 2020-09-24 00:32:54 +00:00
eb0ec04199 fix(core): update 2020-09-24 00:32:54 +00:00
ffd5eb2e52 1.0.22 2020-09-23 23:54:46 +00:00
c432079a70 fix(core): update 2020-09-23 23:54:46 +00:00
16 changed files with 4478 additions and 11310 deletions

View File

@ -12,30 +12,38 @@ stages:
- release
- metadata
before_script:
- pnpm install -g pnpm
- pnpm install -g @shipzone/npmci
- npmci npm prepare
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci git mirror
tags:
- lossless
- docker
- notpriv
audit:
# ====================
# security stage
# ====================
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high
- npmci command npm config set registry https://registry.npmjs.org
- npmci command pnpm audit --audit-level=high --prod
tags:
- lossless
- docker
- notpriv
allow_failure: true
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci command npm config set registry https://registry.npmjs.org
- npmci command pnpm audit --audit-level=high --dev
tags:
- lossless
- docker
allow_failure: true
# ====================
# test stage
@ -44,28 +52,22 @@ audit:
testStable:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- priv
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci command npm run build
- npmci npm build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- notpriv
release:
stage: release
@ -85,11 +87,12 @@ release:
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g tslint typescript
- npmci command npm install -g typescript
- npmci npm prepare
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- lossless
- docker
@ -109,11 +112,9 @@ trigger:
pages:
stage: metadata
script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci command tsdoc
- npmci command npm run buildDocs
tags:
- lossless
- docker

24
.vscode/launch.json vendored
View File

@ -2,28 +2,10 @@
"version": "0.2.0",
"configurations": [
{
"name": "current file",
"type": "node",
"command": "npm test",
"name": "Run npm test",
"request": "launch",
"args": [
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
"type": "node-terminal"
}
]
}

View File

@ -15,7 +15,7 @@
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm"]
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}

View File

@ -2,17 +2,31 @@
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "apiglobal",
"githost": "code.foss.global",
"gitscope": "api.global",
"gitrepo": "test-sdk",
"shortDescription": "an sdk for testing ag handlers",
"npmPackagename": "@apiglobal/test-sdk",
"description": "A software development kit for testing API Gateway handlers.",
"npmPackagename": "@api.global/test-sdk",
"license": "MIT",
"projectDomain": "api.global"
"projectDomain": "api.global",
"keywords": [
"API testing",
"SDK",
"development tools",
"API Gateway",
"server simulation",
"handlers testing",
"automated testing",
"TypeScript",
"Node.js"
]
}
},
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
}
}

11183
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,29 +1,30 @@
{
"name": "@apiglobal/test-sdk",
"version": "1.0.21",
"name": "@api.global/test-sdk",
"version": "2.0.2",
"private": false,
"description": "an sdk for testing ag handlers",
"description": "A software development kit for testing API Gateway handlers.",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"author": "Lossless GmbH",
"license": "MIT",
"scripts": {
"test": "(tstest test/ --web)",
"build": "(tsbuild --web)"
"build": "(tsbuild --web --allowimplicitany)",
"buildDocs": "tsdoc"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.25",
"@gitzone/tstest": "^1.0.44",
"@pushrocks/tapbundle": "^3.2.9",
"@types/node": "^14.11.2",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
"@gitzone/tsrun": "^1.2.39",
"@gitzone/tstest": "^1.0.52",
"@pushrocks/tapbundle": "^5.0.4",
"@types/node": "^18.15.3"
},
"dependencies": {
"@apiglobal/sdk": "^1.0.13",
"@apiglobal/typedrequest": "^1.0.43",
"@apiglobal/typedrequest-interfaces": "^1.0.15",
"@pushrocks/smartexpress": "^3.0.76",
"@apiglobal/sdk": "^2.0.1",
"@apiglobal/typedrequest": "^2.0.12",
"@apiglobal/typedrequest-interfaces": "^2.0.1",
"@pushrocks/qenv": "^5.0.2",
"@pushrocks/smartexpress": "^4.0.28",
"@pushrocks/smartobject": "^1.0.4"
},
"files": [
@ -37,5 +38,20 @@
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
],
"type": "module",
"keywords": [
"API testing",
"SDK",
"development tools",
"API Gateway",
"server simulation",
"handlers testing",
"automated testing",
"TypeScript",
"Node.js"
]
}
}

4232
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

1
readme.hints.md Normal file
View File

@ -0,0 +1 @@

140
readme.md
View File

@ -1,39 +1,123 @@
# @apiglobal/test-sdk
# @api.global/test-sdk
an sdk for testing ag handlers
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@apiglobal/test-sdk)
* [gitlab.com (source)](https://gitlab.com/apiglobal/test-sdk)
* [github.com (source mirror)](https://github.com/apiglobal/test-sdk)
* [docs (typedoc)](https://apiglobal.gitlab.io/test-sdk/)
## Install
To install `@api.global/test-sdk`, you need to have Node.js and npm installed. Follow these steps to install it:
## Status for master
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/apiglobal/test-sdk/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/apiglobal/test-sdk/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@apiglobal/test-sdk)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/apiglobal/test-sdk)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@apiglobal/test-sdk)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@apiglobal/test-sdk)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@apiglobal/test-sdk)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
```bash
npm install @api.global/test-sdk --save
```
This will add `@api.global/test-sdk` to your project's dependencies.
## Usage
This document provides a comprehensive guide on how to effectively utilize the `@api.global/test-sdk` module in your project. We will explore various use cases, demonstrate the SDK's capabilities through code examples, and ensure a thorough understanding of its features. This guide assumes that you have basic knowledge of TypeScript and are familiar with the concepts of asynchronous programming.
Use TypeScript for best in class intellisense
### Getting Started
## Contribution
First, ensure that you are importing the SDK's functionalities as follows:
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
```typescript
import { AgTestServer, createTestServer, stopTestServer } from '@api.global/test-sdk';
```
For further information read the linked docs at the top of this readme.
### Creating and Starting a Test Server
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
The `@api.global/test-sdk` allows for the creation of test servers with custom handlers. Here's how to set it up:
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)
```typescript
import { createTestServer } from '@api.global/test-sdk';
// Your custom handler should extend from AAgHandler
class MyCustomHandler extends AAgHandler<any> {
constructor(envManagerArg: AgEnvironment) {
super(envManagerArg);
this.slug = 'mycustomhandler'; // Define a unique slug for your handler
}
// Implement required handler methods here
}
async function setupTestServer() {
const testServer = await createTestServer(MyCustomHandler);
console.log('Test server started successfully');
return testServer;
}
```
### Sending Requests to the Test Server
With the test server running, you can now simulate requests. Let's demonstrate how to send a request to the custom handler and evaluate the response:
```typescript
import { testFire } from '@api.global/test-sdk';
async function testRequest() {
const testResponse = testFire<MyCustomHandler, MyRequestInterface>(
'mycustomhandler', // The slug of your handler
'POST', // The HTTP method
{ // The request body
key: 'value'
}
);
// Expecting a response from the server
const expectedResponse = await testResponse.expect({
expectedKey: 'expectedValue'
});
console.log('The expected response was received:', expectedResponse);
}
```
### Stopping the Test Server
It's important to properly shut down the test server once your testing is complete to free up resources:
```typescript
async function shutdownTestServer() {
await stopTestServer();
console.log('Test server stopped successfully');
}
```
### Full Example
Here's how everything comes together in a script:
```typescript
import { AgTestServer, createTestServer, stopTestServer, testFire } from '@api.global/test-sdk';
class MyCustomHandler extends AAgHandler<any> {
// Implementation of the custom handler...
}
async function main() {
const server = await setupTestServer();
await testRequest();
await shutdownTestServer();
}
main().catch(console.error);
```
This guide provides a foundational understanding of how to utilize `@api.global/test-sdk` for testing purposes. Through the creation of a test server, the execution of requests, and the evaluation of responses, developers can simulate real-world scenarios and ensure that their applications behave as expected in a controlled environment.
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.

View File

@ -1,5 +1,5 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as testSdk from '../ts/index';
import * as testSdk from '../ts/index.js';
let testServer: testSdk.AgTestServer;

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@apiglobal/test-sdk',
version: '2.0.2',
description: 'an sdk for testing ag handlers'
}

View File

@ -1,18 +1,24 @@
import * as plugins from './test-sdk.plugins';
import { AgTestServer } from './test-sdk.classes.testserver';
import * as plugins from './test-sdk.plugins.js';
import { AgTestServer } from './test-sdk.classes.testserver.js';
import { AAgHandler } from '@apiglobal/sdk';
export {
AgTestServer
};
export { AgTestServer };
let testServer: AgTestServer;
export const createTestServer = async (handlerArg: { new(envHandler: plugins.agSdk.AgEnvironment): plugins.agSdk.AAgHandler<any> }) => {
let handler: AAgHandler<any>;
export const createTestServer = async (handlerArg: {
new (envManagerArg: plugins.agSdk.AgEnvironment): plugins.agSdk.AAgHandler<any>;
}) => {
class AgEnvironement extends plugins.agSdk.AgEnvironment {
public qenv = new plugins.qenv.Qenv('./', './.nogit');
public async getEnvVar(nameArg: string) {
return '';
return this.qenv.getEnvVarOnDemand(nameArg);
}
}
testServer = new AgTestServer(new handlerArg(new AgEnvironement()));
handler = new handlerArg(new AgEnvironement());
console.log(`now checking requirements for handler with slug ${handler.slug}...`);
await handler.checkRequirements();
testServer = new AgTestServer(handler);
await testServer.start();
return testServer;
};
@ -38,7 +44,10 @@ export const testFire = <
const responsePromise = typedRequest.fire(requestArg);
const expect = async (expectedResponseArg: T['response']) => {
const actualResponse = await responsePromise;
const comparisonResult = plugins.smartobject.compareObjects(expectedResponseArg, actualResponse);
const comparisonResult = plugins.smartobject.compareObjects(
expectedResponseArg,
actualResponse
);
let throwErrorBool = false;
if (comparisonResult.divergingProperties.length > 0) {
console.log(`The following properties diverged:`);
@ -57,17 +66,23 @@ export const testFire = <
throwErrorBool = true;
}
if (throwErrorBool) {
console.log('Result: response did not comply');
console.log('-> expected:');
console.log(expectedResponseArg);
console.log('-> but actually received:');
console.log(actualResponse);
throw new Error('response did not comply');
}
return actualResponse;
};
return {
expect
expect,
};
};
export const stopTestServer = async () => {
if (testServer) {
await testServer.stop();
await handler.stop();
}
};

View File

@ -1,4 +1,4 @@
import * as plugins from './test-sdk.plugins';
import * as plugins from './test-sdk.plugins.js';
export class AgTestServer {
public handlers: Array<plugins.agSdk.AAgHandler<any>> = [];

View File

@ -6,7 +6,8 @@ import * as typedrequestInterfaces from '@apiglobal/typedrequest-interfaces';
export { agSdk, typedrequest, typedrequestInterfaces };
// pushrocks scope
import * as qenv from '@pushrocks/qenv';
import * as smartexpress from '@pushrocks/smartexpress';
import * as smartobject from '@pushrocks/smartobject';
export { smartexpress, smartobject };
export { qenv, smartexpress, smartobject };

14
tsconfig.json Normal file
View File

@ -0,0 +1,14 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true
},
"exclude": [
"dist_*/**/*.d.ts"
]
}

View File

@ -1,17 +0,0 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}