-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
250 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
}) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters