---
title: "@api.global/test-sdk"
---
# @api.global/test-sdk
an sdk for testing ag handlers

## Install
To install `@api.global/test-sdk`, you need to have Node.js and npm installed. Follow these steps to install it:

```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.

### Getting Started

First, ensure that you are importing the SDK's functionalities as follows:

```typescript
import { AgTestServer, createTestServer, stopTestServer } from '@api.global/test-sdk';
```

### Creating and Starting a Test Server

The `@api.global/test-sdk` allows for the creation of test servers with custom handlers. Here's how to set it up:

```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.
