Skip to content

Commit

Permalink
docs: added docs folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Raymond Ottun committed Sep 28, 2021
1 parent ca68b88 commit 0188272
Show file tree
Hide file tree
Showing 17 changed files with 932 additions and 0 deletions.
79 changes: 79 additions & 0 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const { description } = require('../../package')
const { version } = require('../../package')

module.exports = {

base: '/deputy/',

/**
* Ref:https://v1.vuepress.vuejs.org/config/#title
*/
title: 'Deputy',
/**
* Ref:https://v1.vuepress.vuejs.org/config/#description
*/
description,

/**
* Extra tags to be injected to the page HTML `<head>`
*
* ref:https://v1.vuepress.vuejs.org/config/#head
*/
head: [
['meta', { name: 'theme-color', content: '#3eaf7c' }],
['meta', { name: 'apple-mobile-web-app-capable', content: 'yes' }],
['meta', { name: 'apple-mobile-web-app-status-bar-style', content: 'black' }]
],

/**
* Theme configuration, here is the default theme configuration for VuePress.
*
* ref:https://v1.vuepress.vuejs.org/theme/default-theme-config.html
*/
themeConfig: {
version,
repo: 'sayjava/deputy',
editLinks: false,
docsDir: 'docs',
editLinkText: '',
lastUpdated: false,
logo: '/assets/img/landing.svg',
nav: [
{
text: 'Start',
link: '/start',
},
{
text: 'Guide',
link: '/guide'
},
{
text: 'Assertions',
link: '/assertions'
},
{
text: 'API',
link: '/api'
}
],
sidebar: [
'/',
'/start',
'/guide',
'/assertions',
'/api',
'/proxy',
'/https'
]
},

/**
* Apply plugins,ref:https://v1.vuepress.vuejs.org/zh/plugin/
*/
plugins: [
'@vuepress/plugin-back-to-top',
'@vuepress/plugin-medium-zoom',
],

evergreen: true
}
49 changes: 49 additions & 0 deletions docs/.vuepress/public/assets/img/landing.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions docs/.vuepress/styles/index.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Custom Styles here.
*
* ref:https://v1.vuepress.vuejs.org/config/#index-styl
*/

.home .hero img
max-width 450px!important
10 changes: 10 additions & 0 deletions docs/.vuepress/styles/palette.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Custom palette here.
*
* ref:https://v1.vuepress.vuejs.org/zh/config/#palette-styl
*/

$accentColor = #3F598A
$textColor = #2c3e50
$borderColor = #eaecef
$codeBgColor = #282c34
72 changes: 72 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
id: api
title: API
sidebar_label: API
slug: /api
has_toc: true
nav_order: 4
---

## Behave Server API

Behave Server exposes a set of APIs that are useful for manipulating behaviors or retrieving records from
Behave Server.

## Behaviors

### List

`GET /_/api/behaviors` will list all the configured behaviors on the server for example:

```shell script
curl http://localhost:8080/_/api/behaviors
```

### Create

`PUT http://localhost:8080/_/api/behaviors` will create new behaviors on the server, for example:

```shell script
# Responds with a 201
curl -X PUT http://localhost:8080/_/api/behaviors -d '
- requests:
path: "/hi"
- requests:
path: "/halo"
'
```

see more about [Behaviors](guide.md) here

### Delete

`DELETE http://localhost:8080/_/api/behaviors/:id` will delete the behavior with the specified id, for example:

```shell
# Responds with a 201
curl -X DELETE http://localhost:8080/_/api/behaviors/:id
```

see more about [Behaviors](guide.md) here


## Records

The server stores all the received requests alongside the matched Behaviors in memory

### List

`GET http://localhost:8080/_/api/records` will list all the records received by the server, for example:

```shell
# Responds with a 200 and a list of requests and matched behaviors
curl -X GET http://localhost:8080/_/api/records
```

## Delete
`PUT http://localhost:8080/_/api/reset` will delete all the records and behaviors, for example:

```shell
# Clear all records and behaviors
curl -X PUT http://localhost:8080/_/api/reset
```
130 changes: 130 additions & 0 deletions docs/assertions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
---
id: assertions
title: Assertions
sidebar_label: Assertions
slug: /assertions
has_toc: true
sidebarDepth: 3
---
# Request Assertions

`behave` includes a feature to validate requests that it has received and matched successfully. Requests that are not matched by any configured Behavior on the server will result in a validation fail.

There are two types of validations that `behave` supports, `assertions` and `sequence` validations.

## Assertions

The server can validate how many times a request is received and matched if at all.

If the validation passes, the server returns an `HTTP 201` but if fails, the server returns an `HTTP 406` with reason why it fails

### Request was matched at least once

Check if the requests have been received and matched at least once

```shell
# Responds with 201
curl -X PUT http://localhost:8080/_/api/requests/assert -d '
- path: /tasks/123
- path: /tasks/12
'
```

### Requests was matched by an upper limit count

Check if the requests have been received and matched `at most` twice

```shell
# Responds with 201 if it were matched
curl -X PUT http://localhost:8080/_/api/requests/assert -d '
- path: /tasks/123
count:
atMost: 2
'
```

### Requests was matched by a lower limit count

Check if the requests have been received and matched `at least` twice

```shell
# Responds with 201 if it were matched
curl -X PUT http://localhost:8080/_/api/requests/assert -d '
- path: /tasks/123
count:
atLeast: 2
'
```

### Request was matched by an exact number

Check if the requests have been received exactly twice

```shell
# Responds with 201 if it were matched
curl -X PUT http://localhost:8080/_/api/requests/assert -d '
- path: /tasks/123
count:
atMost: 2
atLeast: 2
'
```

### Request was never received

Check if the requests was never matched

```shell
# Responds with 201 if it were matched
curl -X PUT http://localhost:8080/_/api/requests/assert -d '
- path: /tasks/123
count:
atMost: 0
'
```

### Requests were received at least at an interval

Check if this request was received more than once and at least `time` in seconds apart. This will implicitly require that at least 2 requests was received and matched

```shell
# Check that requests were received at least 10 seconds apart
# Responds with 201 if it were matched
curl -X PUT http://localhost:8080/_/api/requests/interval -d '
requests:
- path: /users/123
- path: /tasks/123
interval:
atLeast: 10
'
```

### Requests were received at most at an interval

Check if this request was received more than once and at least `time` in seconds apart. This will implicitly require that at most 2 requests was received and matched

```shell
# Check that requests were received at most 10 seconds apart
# Responds with 201 if it were matched
curl -X PUT http://localhost:8080/_/api/requests/assert -d '
- path: /tasks/123
interval:
atMost: 10
'
```

## Request Sequence Assertions

The `behave` can also match the order in which requests are received by the server.

### Requests were received in a particular order

Check if the requests were received in the specific order

```shell
# Responds with 201 if it were matched
curl -X PUT http://localhost:8080/_/api/requests/sequence -d '
- path: /tasks/123
- path: /tasks/123/docs/icon.png
'
```

0 comments on commit 0188272

Please sign in to comment.