Skip to content

Added tests with documentation of methods in wrapper #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules/
coverage/
.nyc_output/
74 changes: 69 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Wrapper library for Topcoder Bus API

```
const busApi = require('tc-bus-api-wrapper')
busApi(_.pick(config,
const busApiClient = busApi(_.pick(config,
['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME',
'AUTH0_CLIENT_ID', 'AUTH0_CLIENT_SECRET', 'BUSAPI_URL',
'KAFKA_ERROR_TOPIC']))
Expand All @@ -30,17 +30,81 @@ busApi(_.pick(config,
- AUTH0_CLIENT_ID

- BUSAPI_URL - Bus API URL. E.g. `https://api.topcoder-dev.com/v5`

- KAFKA_ERROR_TOPIC - Error topic in Kafka to which error message need to be posted


3. Every function in this wrapper will return a promise, Handling promises is at the caller end. Call the functions with appropriate arguments

E.g.

```
const result = yield busApiClient.getTopics()
busApiClient
.getTopics()
.then(result => console.log(result.body, result.status))
.catch(err => console.log(err))

yield busApiClient.postEvent(reqBody)
await busApiClient.postEvent(reqBody)
```

Refer `index.js` for the list of available wrapper functions
Refer `index.js` for the list of available wrapper functions

## Documentation for Bus API wrapper methods

All URIs are relative to **BUSAPI_URL** configuration variable.

Method | HTTP request | Description
------------- | ------------- | -------------
[**postEvent**](docs/EventsApi.md#postEvent) | **POST** /bus/events | Post event to the message bus.
[**postError**](docs/EventsApi.md#postError) | **POST** /bus/events | Post error event to the message bus. This method is same as postEvent except that topic will be set by the wrapper itself.
[**getHealth**](docs/HealthchecksApi.md#getHealth) | **GET** /bus/health | Check API is healthy.
[**headHealth**](docs/HealthchecksApi.md#headHealth) | **HEAD** /bus/health | Get only response status and headers information but no response body for the endpoint.
[**clearPlaceholdersCache**](docs/PlaceholdersApi.md#clearPlaceholdersCache) | **DELETE** /bus/placeholders | Clear placeholders cache.
[**createService**](docs/ServiceApi.md#createService) | **POST** /bus/services | Create a service.
[**createServicePayload**](docs/ServiceApi.md#createServicePayload) | **POST** /bus/services/{serviceName}/payloads | Create the service payload.
[**deleteService**](docs/ServiceApi.md#deleteService) | **DELETE** /bus/services/{serviceName} | Delete the service.
[**deleteServicePayload**](docs/ServiceApi.md#deleteServicePayload) | **DELETE** /bus/services/{serviceName}/payloads/{payloadName} | Delete the service payload.
[**getService**](docs/ServiceApi.md#getService) | **GET** /bus/services/{serviceName} | Get the service.
[**getServicePayload**](docs/ServiceApi.md#getServicePayload) | **GET** /bus/services/{serviceName}/payloads/{payloadName} | Get the service payload.
[**getServicePayloads**](docs/ServiceApi.md#getServicePayloads) | **GET** /bus/services/{serviceName}/payloads | Search the service payloads.
[**getServices**](docs/ServiceApi.md#getServices) | **GET** /bus/services | Get all services.
[**headService**](docs/ServiceApi.md#headService) | **HEAD** /bus/services/{serviceName} | Get only response status and headers information but no response body for the endpoint.
[**headServicePayload**](docs/ServiceApi.md#headServicePayload) | **HEAD** /bus/services/{serviceName}/payloads/{payloadName} | Get only response status and headers information but no response body for the endpoint.
[**headServicePayloads**](docs/ServiceApi.md#headServicePayloads) | **HEAD** /bus/services/{serviceName}/payloads | Get only response status and headers information but no response body for the endpoint.
[**headServices**](docs/ServiceApi.md#headServices) | **HEAD** /bus/services | Get only response status and headers information but no response body for the endpoint.
[**patchService**](docs/ServiceApi.md#patchService) | **PATCH** /bus/services/{serviceName} | Partially update the service.
[**patchServicePayload**](docs/ServiceApi.md#patchServicePayload) | **PATCH** /bus/services/{serviceName}/payloads/{payloadName} | Partially update the payload.
[**updateService**](docs/ServiceApi.md#updateService) | **PUT** /bus/services/{serviceName} | Update the service.
[**updateServicePayload**](docs/ServiceApi.md#updateServicePayload) | **PUT** /bus/services/{serviceName}/payloads/{payloadName} | Update the service payload.
[**getTopics**](docs/TopicsApi.md#getTopics) | **GET** /bus/topics | Get topics.
[**headTopics**](docs/TopicsApi.md#headTopics) | **HEAD** /bus/topics | Get only response status and headers information but no response body for the endpoint.

## Authorization

Bus API wrapper internally generates a **JWT token using Auth0 credentials** and pass it in the `Authorization` header.

## Running tests

Following environment variables need to be set up before running the tests

```
- TEST_AUTH0_URL
- TEST_AUTH0_AUDIENCE
- TEST_AUTH0_CLIENT_ID
- TEST_AUTH0_CLIENT_SECRET
- TEST_BUS_API_URL
- TEST_KAFKA_ERROR_TOPIC
```

Refer to Step # 2 in [this section](#how-to-use-this-wrapper) to learn more about the configuration variables.

To run the tests alone, execute the command

```
npm run test
```

To run tests with coverage report, execute the command

```
npm run cov
```
10 changes: 10 additions & 0 deletions docs/EventPayload.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Event Payload

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**topic** | **String** | Topic name should be a dot separated fully qualified name i.e. domain.type.operation. |
**originator** | **String** | Service repository name, from where message is published. |
**timestamp** | **Date** | Timestamp at which message is published. The date-time notation as defined by RFC 3339, section 5.6, for example, 2018-04-13T00:00:00Z |
**mimeType** | **String** | Mime-type for 'payload'. |
**payload** | **Object** | Actual payload depending on mime-type for consumer. |
9 changes: 9 additions & 0 deletions docs/EventPayloadWoTopic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Event Payload Without Topic

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**originator** | **String** | Service repository name, from where message is published. |
**timestamp** | **Date** | Timestamp at which message is published. The date-time notation as defined by RFC 3339, section 5.6, for example, 2018-04-13T00:00:00Z |
**mimeType** | **String** | Mime-type for 'payload'. |
**payload** | **Object** | Actual payload depending on mime-type for consumer. |
111 changes: 111 additions & 0 deletions docs/EventsApi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Events Api

All URIs are relative to **BUSAPI_URL** configuration variable.

Method | HTTP request | Description
------------- | ------------- | -------------
[**postEvent**](EventsApi.md#postEvent) | **POST** /bus/events | Post event to the message bus.
[**postError**](EventsApi.md#postError) | **POST** /bus/events | Post error event to the message bus. Topic will be set by wrapper itself.

<a name="postEvent"></a>
# **postEvent**
> postEvent(body)

Post an event to the message bus.

### Example
```javascript
const busApi = require('tc-bus-api-wrapper')
const busApiClient = busApi(_.pick(config,
['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME',
'AUTH0_CLIENT_ID', 'AUTH0_CLIENT_SECRET', 'BUSAPI_URL',
'KAFKA_ERROR_TOPIC']))

const reqBody = {
'topic': 'test.topic.1',
'originator': 'tester',
'timestamp': '2018-05-20T07:00:30.123Z',
'mime-type': 'application/json',
'payload': { // Payload varies depending on the event
'name': 'test'
}
}
// Promise model
busApiClient
.postEvent(reqBody)
.then(result => console.log(result.body, result.status))
.catch(err => console.log(err))

// Async / await model
await busApiClient.postEvent(reqBody)
```

### Parameters

Name | Type | Description
------------- | ------------- | -------------
**body** | [**Event Payload**](EventPayload.md)| Payload of an event

### Return type

null (empty response body)

### Authorization

[Bearer](../README.md#authorization)

### HTTP request headers

- **Content-Type**: application/json
- **Accept**: application/json

<a name="postError"></a>
# **postError**
> postError(body)

Post error event to the message bus.

### Example
```javascript
const busApi = require('tc-bus-api-wrapper')
const busApiClient = busApi(_.pick(config,
['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME',
'AUTH0_CLIENT_ID', 'AUTH0_CLIENT_SECRET', 'BUSAPI_URL',
'KAFKA_ERROR_TOPIC']))

const reqBody = {
'originator': 'tester',
'timestamp': '2018-05-20T07:00:30.123Z',
'mime-type': 'application/json',
'payload': { // Payload varies depending on the event
'name': 'test'
}
}
// Promise model
busApiClient
.postError(reqBody)
.then(result => console.log(result.body, result.status))
.catch(err => console.log(err))

// Async / await model
await busApiClient.postError(reqBody)
```

### Parameters

Name | Type | Description
------------- | ------------- | -------------
**body** | [**Event Payload Without Topic**](EventPayloadWoTopic.md)| Payload of error event without topic

### Return type

null (empty response body)

### Authorization

[Bearer](../README.md#authorization)

### HTTP request headers

- **Content-Type**: application/json
- **Accept**: application/json
7 changes: 7 additions & 0 deletions docs/ExtendedService.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Extended Service

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**serviceId** | **String** | The service id. |
**service** | [**Service**](Service.md) | Service definition | Attributes from Service will be merged into this object
6 changes: 6 additions & 0 deletions docs/HealthCheckStatus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Health Check Status

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**health** | **String** | Health check status. | [default to &#39;ok&#39;]
90 changes: 90 additions & 0 deletions docs/HealthchecksApi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Healthchecks Api

All URIs are relative to **BUSAPI_URL** configuration variable.

Method | HTTP request | Description
------------- | ------------- | -------------
[**getHealth**](HealthchecksApi.md#getHealth) | **GET** /bus/health | Check if API is healthy.
[**headHealth**](HealthchecksApi.md#headHealth) | **HEAD** /bus/health | Get only response status and headers information but no response body for the endpoint.


<a name="getHealth"></a>
# **getHealth**
> HealthCheckStatus getHealth()

Check if API is healthy.

### Example
```javascript
const busApi = require('tc-bus-api-wrapper')
const busApiClient = busApi(_.pick(config,
['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME',
'AUTH0_CLIENT_ID', 'AUTH0_CLIENT_SECRET', 'BUSAPI_URL',
'KAFKA_ERROR_TOPIC']))

// Promise model
busApiClient
.getHealth()
.then(result => console.log(result.body, result.status))
.catch(err => console.log(err))

// Async / await model
const result = await busApiClient.getHealth()
```

### Parameters
This endpoint does not need any parameter.

### Return type

[**Health Check Status**](HealthCheckStatus.md)

### Authorization

No authorization required

### HTTP request headers

- **Content-Type**: application/json
- **Accept**: application/json

<a name="headHealth"></a>
# **headHealth**
> headHealth()

Get response status and headers information for the endpoint. It does not contain response body.

### Example
```javascript
const busApi = require('tc-bus-api-wrapper')
const busApiClient = busApi(_.pick(config,
['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME',
'AUTH0_CLIENT_ID', 'AUTH0_CLIENT_SECRET', 'BUSAPI_URL',
'KAFKA_ERROR_TOPIC']))

// Promise model
busApiClient
.headHealth()
.then(result => console.log(result.body, result.status)) // Body will be empty
.catch(err => console.log(err))

// Async / await model
const result = await busApiClient.headHealth()
```

### Parameters
This endpoint does not need any parameter.

### Return type

null (empty response body)

### Authorization

No authorization required

### HTTP request headers

- **Content-Type**: application/json
- **Accept**: application/json

9 changes: 9 additions & 0 deletions docs/Payload.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Payload

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**name** | **String** | The payload name. | [optional]
**topics** | **[String]** | The list of topics for a payload. |
**payloadMimeType** | **String** | The payload mime type. |
**payloadFormat** | **Object** | The payload format. |
Loading