Skip to content

Commit

Permalink
feat: add test, validate docs (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
Idered authored Nov 9, 2017
1 parent 0ae9a7c commit 1f0e64a
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 27 deletions.
8 changes: 5 additions & 3 deletions packages/lib-js-client/readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
![](https://raw.githubusercontent.com/Syncano/art/0b650278a83aa20c1a597b0f2f3d89355156e694/syncano-client/repo-banner.png)
![][Banner]

[![npm](https://img.shields.io/npm/v/@syncano/client.svg)](https://www.npmjs.org/package/@syncano/client)
<!-- [![CircleCI](https://circleci.com/gh/Syncano/syncano-client-js.svg?style=shield&circle-token=2efee697e0cee80591aec86e022a9dbe0b3b25b8)](https://circleci.com/gh/Syncano/syncano-client-js) [![codecov](https://codecov.io/gh/Syncano/syncano-client-js/branch/devel/graph/badge.svg)](https://codecov.io/gh/Syncano/syncano-client-js) -->

# Syncano Client Library

Expand All @@ -10,8 +9,11 @@ This library enables you to interact with the Syncano Sockets via Javascript.
- **Socket Connection** - Communicate with sockets
- **Realtime Channels** - React on changes in socket channels

[![Read Documentation](https://raw.githubusercontent.com/Syncano/art/0b650278a83aa20c1a597b0f2f3d89355156e694/syncano-client/read-documentation.png)](docs/readme.md)
[![Read Documentation][read-documentation.png]](docs/readme.md)

## License

Syncano Server Library is MIT licensed. See [license](license.md).

[Banner]: https://raw.githubusercontent.com/Syncano/art/master/syncano-node/repo-banner-client.png
[read-documentation.png]: https://raw.githubusercontent.com/Syncano/art/master/syncano-node/read-documentation.png
32 changes: 16 additions & 16 deletions packages/lib-js-core/docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@
- [Usage in Syncano Socket](#usage-in-syncano-socket)
- [Installation](#installation)
- The Basics
- [Data](docs/basics/data.md)
- [Users](docs/basics/users.md)
- [Responses](docs/basics/responses.md)
- [Endpoints](docs/basics/endpoints.md)
- [Channels](docs/basics/channels.md)
- [Events](docs/basics/events.md)
- [Logger](docs/basics/logger.md)
- [Data](basics/data.md)
- [Users](basics/users.md)
- [Responses](basics/responses.md)
- [Endpoints](basics/endpoints.md)
- [Channels](basics/channels.md)
- [Events](basics/events.md)
- [Logger](basics/logger.md)

- <details>
<summary>Architecture Concepts</summary>

- [Socket](docs/architecture/socket.md)*
- [Socket Context](docs/architecture/socket-context.md)*
- [Socket](architecture/socket.md)*
- [Socket Context](architecture/socket-context.md)*
</details>

- <details>
<summary>Syncano Core</summary>

- [Syncano Account](docs/core/syncano-account.md)*
- [Syncano Backups](docs/core/syncano-backups.md)*
- [Syncano Classes](docs/core/syncano-classes.md)*
- [Syncano Hostings](docs/core/syncano-hostings.md)*
- [Syncano Instances](docs/core/syncano-instances.md)*
- [Syncano Sockets](docs/core/syncano-sockets.md)*
- [Syncano Traces](docs/core/syncano-traces.md)*
- [Syncano Account](core/syncano-account.md)*
- [Syncano Backups](core/syncano-backups.md)*
- [Syncano Classes](core/syncano-classes.md)*
- [Syncano Hostings](core/syncano-hostings.md)*
- [Syncano Instances](core/syncano-instances.md)*
- [Syncano Sockets](core/syncano-sockets.md)*
- [Syncano Traces](core/syncano-traces.md)*
</details>

`*` - TODO
Expand Down
File renamed without changes.
12 changes: 7 additions & 5 deletions packages/lib-js-core/readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
![](https://raw.githubusercontent.com/Syncano/art/eb37cb6f744f25766121189c206f0872490fd6eb/syncano-core/repo-banner.png)
![][Banner]

[![npm](https://img.shields.io/npm/v/syncano-server.svg)](https://www.npmjs.org/package/syncano-server) [![CircleCI](https://circleci.com/gh/Syncano/syncano-server-js/tree/devel.svg?style=shield&circle-token=0340c11444db6f3dc227cf310f4d8ff1bd90dee8)](https://circleci.com/gh/Syncano/syncano-server-js/tree/devel)
[![codecov](https://codecov.io/gh/Syncano/syncano-server-js/branch/devel/graph/badge.svg)](https://codecov.io/gh/Syncano/syncano-server-js)
[![npm](https://img.shields.io/npm/v/@syncano/core.svg)](https://www.npmjs.org/package/@syncano/core)

# Syncano Server-side Library

Expand All @@ -12,8 +11,11 @@ to communicate with **Syncano Core Services**. Syncano provides various Core Ser
- **Event Loop (events)** - service to emit events which can be caught by any Socket
- **Realtime Channels (channels)** - implement publish/subscribe model for realtime communication

[![Read Documentation](https://raw.githubusercontent.com/Syncano/art/eb37cb6f744f25766121189c206f0872490fd6eb/syncano-core/read-documentation.png)](docs/README.md)
[![Read Documentation][read-documentation.png]](docs/README.md)

## License

Syncano Server Library is MIT licensed. See [LICENSE](LICENSE.md).
Syncano Server Library is MIT licensed. See [license](license.md).

[Banner]: https://raw.githubusercontent.com/Syncano/art/master/syncano-node/repo-banner-core.png
[read-documentation.png]: https://raw.githubusercontent.com/Syncano/art/master/syncano-node/read-documentation.png
104 changes: 104 additions & 0 deletions packages/lib-js-test/docs/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Documentation

- Getting Started
- [Usage](#usage)
- [Learn more](#learn-more)
- [Installation](#installation)
- [Methods](#methods)

# Getting Started

## Usage

```js
import {run, generateMeta} from '@syncano/test'
```

```js
run('generate', {args, meta})
.then(response => response.is('success'))
.then(response => {
assert.propertyVal(response, 'data', '<p>Hello, my name is John</p>')
})
```

## Learn more

More examples how to create tests and use Syncano Test library you can find in the [Tests section](https://cookbook.syncano.io/) of the Cookbook.

## Installation

**Installing from NPM**

```bash
npm i @syncano/test --save
```

# Methods

| Name | Description |
| ---------------------------------------- | ------------------------------------------------- |
| [generateMeta](#generatemeta) | Generate radnom meta data |
| [run](#runendpointname-args-meta-config) | Call socket locally |
| [response.is](#responseisresponsename) | Check if response match response from syncano.yml |

## `generateMeta()`

Generating random metadata. Usually you don't need to use this method and instead of it pass additional metadata keys to the run method. Those examples are equal:

```js
run('generate', {args, meta: {newMetaKey: 'test value'}})
```

```js
const meta = generateMeta()

meta.newMetaKey = 'test value'

run('generate', {args, meta})
```


## `run(endpointName, options?)`

| Type | Name | Default | Description |
| ------ | -------------------- | ------- | ----------------------------- |
| string | **`endpointName`** | | |
| object | **`options`** | {} | |
| object | **`options.args`** | {} | Parameters passed to endpoint |
| object | **`options.meta`** | {} | Endpoint configuration |
| object | **`options.config`** | {} | Socket configuration |

```js
run('generate', {args, meta})
.then(response => {
assert.propertyVal(response, 'data', '<p>Hello, my name is John</p>')
})
```

## `response.is(responseName)`

| Type | Name | Default | Description |
| ------ | ------------------ | ------- | ------------------------------ |
| string | **`responseName`** | | Response name from syncano.yml |

Check if the response is valid. This operation verifies response based on schema definition in `socket.yml`:

- exit code
- MIME type
- arguments

```js
run('search', {args: {post_code: '0161'}})
.then(response => response.is('success'))
.then(response => {
assert.propertyVal(response.data, 'city', 'Oslo')
assert.propertyVal(response.data, 'municipality', 'Oslo')
assert.propertyVal(response.data, 'county', 'Oslo')
assert.propertyVal(response.data, 'category', 'G')
done()
})
.catch(err => {
done(err)
})
```
File renamed without changes.
16 changes: 16 additions & 0 deletions packages/lib-js-test/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
![][Banner]

[![npm](https://img.shields.io/npm/v/@syncano/test.svg)](https://www.npmjs.org/package/@syncano/test)

# Syncano Test Library

This library helps to run endpoints locally for test purposes. During the test whole context (`ctx`) can be generated and passed to the tested endpoint.

[![Read Documentation][read-documentation.png]](docs/readme.md)

## License

Syncano Test Library is MIT licensed. See [license](license.md).

[Banner]: https://raw.githubusercontent.com/Syncano/art/master/syncano-node/repo-banner-test.png
[read-documentation.png]: https://raw.githubusercontent.com/Syncano/art/master/syncano-node/read-documentation.png
58 changes: 58 additions & 0 deletions packages/lib-js-validate/docs/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Documentation

- Getting Started
- [Usage](#usage)
- [Installation](#installation)
- [Methods](#methods)

# Getting Started

## Usage

```js
import Validator from '@syncano/validate'

const validator = new Validator({args, meta, config})
```

## Installation

**Installing from NPM**

```bash
npm i @syncano/validate --save
```

# Methods

| Name | Description |
| ----------------------------------------------------------------------------- | ---------------------------- |
| [validator.validateRequest](#validatorvalidaterequestctx) | Validate incoming parameters |
| [validator.validateResponse](#validatorvalidateresponseresponsetype-response) | Validate endpoint response |

## `validator.validateRequest(ctx)`

| Type | Name | Default | Description |
| ------ | --------- | ------- | --------------------------------------------- |
| object | **`ctx`** | {} | Object containing `args`, `meta` and `config` |

```js
export default ctx => {
validator.validateRequest(ctx)
}
```

## `validator.validateResponse(responseType, response)`

| Type | Name | Default | Description |
| ------ | ------------------ | ------- | --------------------------------------- |
| string | **`responseType`** | | Name of response defined in syncano.yml |
| mixed | **`response`** | | Endpoint response |

```js
export default ctx => {
validator.validateResponse('success', {
messsage: 'Action was successful'
})
}
```
21 changes: 21 additions & 0 deletions packages/lib-js-validate/license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Syncano

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
16 changes: 16 additions & 0 deletions packages/lib-js-validate/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
![][Banner]

[![npm](https://img.shields.io/npm/v/@syncano/validate.svg)](https://www.npmjs.org/package/@syncano/validate)

# Syncano Validate Library

This library is used mainly internally by Syncano Core and Syncano Test libraries. In most of the cases you don't need to use it directly.

[![Read Documentation][read-documentation.png]](docs/readme.md)

## License

Syncano Validate Library is MIT licensed. See [license](license.md).

[Banner]: https://raw.githubusercontent.com/Syncano/art/master/syncano-node/repo-banner-validate.png
[read-documentation.png]: https://raw.githubusercontent.com/Syncano/art/master/syncano-node/read-documentation.png
10 changes: 7 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
![](https://raw.githubusercontent.com/Syncano/art/96584ac4de2859d01fbd7f6ea84825779bd28cd5/syncano-node/repo-banner.png)
![][Banner]

## Syncano Toolkit
- [CLI](packages/cli/readme.md) - Manage Syncano Instances, install and deploy Syncano Sockets
- [Client Library](packages/lib-js-client/docs/readme.md) - Interact with Syncano Sockets via JavaScript
- [Core Library](packages/lib-js-core/docs/readme.md) - Communicate with Syncano Core Services
- [Client Library](packages/lib-js-client/readme.md) - Interact with Syncano Sockets via JavaScript
- [Core Library](packages/lib-js-core/readme.md) - Communicate with Syncano Core Services
- [Test Library](packages/lib-js-test/readme.md) - Run test suites on Syncano Sockets
- [Validate Library](packages/lib-js-validate/readme.md) - Validate requests to Syncano Sockets

Expand All @@ -13,6 +13,8 @@
- [CLI](https://syncano.github.io/syncano-node-cli/#/)
- [Client Library](packages/lib-js-client/docs/readme.md)
- [Core Library](packages/lib-js-core/docs/readme.md)
- [Test Library](packages/lib-js-test/docs/readme.md)
- [Validate Library](packages/lib-js-validate/docs/readme.md)

## Issues

Expand All @@ -27,3 +29,5 @@ Please see our [contributing.md](contributing.md)
## License

MIT. See [license](license.md).

[Banner]: https://raw.githubusercontent.com/Syncano/art/master/syncano-node/repo-banner.png

0 comments on commit 1f0e64a

Please sign in to comment.