mocks: docs, examples, tests

This commit is contained in:
Lloyd Brookes
2015-11-25 20:53:09 +00:00
parent 4150797b24
commit c0a72dbaf2
11 changed files with 338 additions and 58 deletions

View File

@ -1,9 +1,9 @@
{
"mocks": [
{
"route": "/one",
"route": "/",
"response": {
"body": { "id": 1, "name": "whatever" }
"body": "<h1>Welcome to the Mock Responses example</h1>"
}
},
{
@ -15,11 +15,11 @@
},
{
"route": "/three",
"targets": [
"responses": [
{
"request": { "method": "GET" },
"response": {
"body": { "id": 1, "name": "whatever" }
"body": "<h1>Mock response for 'GET' request on /three</h1>"
}
},
{

View File

@ -1,7 +0,0 @@
body {
background-color: #AA3939;
color: #FFE2E2
}
svg {
fill: #000
}

View File

@ -1,8 +0,0 @@
<head>
<link rel="stylesheet" href="css/style.css">
</head>
<h1>Mock responses</h1>
<ul>
<li>list data</li>
</ul>
<script src="bundle.js"></script>

View File

@ -1,9 +0,0 @@
'use strict'
const request = require('req-then')
const $ = document.querySelector.bind(document)
request('http://localhost:8000/tree').then(response => {
$('ul').innerHTML = JSON.parse(response.data).map(tree => {
return `<li>${tree.name}</li>`
}).join('')
})

View File

@ -0,0 +1,3 @@
{
"one": "static data"
}

View File

@ -1,8 +1,5 @@
module.exports = {
response: function (ctx, id, name) {
this.body = {
id: id,
name: name
}
ctx.body = `<h1>id: ${id}, name: ${name}</h1>`
}
}

View File

@ -1,5 +1,7 @@
const fs = require('fs')
module.exports = {
response: {
body: { id: 2, name: 'eucalyptus', maxHeight: 210 }
body: fs.createReadStream(__filename)
}
}