Intial commit.
This commit is contained in:
commit
a69cacdf5e
|
|
@ -0,0 +1 @@
|
|||
node_modules/
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
printWidth: 80
|
||||
tabWidth: 4
|
||||
singleQuote: true
|
||||
useTabs: false
|
||||
trailingComma: none
|
||||
bracketSpacing: true
|
||||
jsxBracketSameLine: true
|
||||
parser: babylon
|
||||
semi: true
|
||||
requirePragma: false
|
||||
proseWrap: always
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
# Beau Faker
|
||||
|
||||
Beau-faker allows you to use faker.js from within Beau.
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
npm i -g beau-faker
|
||||
```
|
||||
|
||||
Don't forget to add faker to your Beau plugins.
|
||||
|
||||
## Usage
|
||||
|
||||
You can let beau know you are using faked values within a request by adding the
|
||||
`FakeIt` key and setting it to `true`.
|
||||
|
||||
```yml
|
||||
endpoint: http://httpbin.org
|
||||
|
||||
plugins:
|
||||
- faker
|
||||
|
||||
POST /anything:
|
||||
alias: anything
|
||||
fakeIt: true
|
||||
payload:
|
||||
name:
|
||||
first: '{{name.firstName}}'
|
||||
last: '{{name.lastName}}'
|
||||
|
||||
address: '{{address.city}}, {{address.state}}'
|
||||
```
|
||||
|
||||
When set to `fakeIt` is set to `true` beau will run
|
||||
[`Faker.faker`](https://github.com/marak/Faker.js/#fakerfake) on every value
|
||||
within that request.
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
endpoint: http://httpbin.org
|
||||
|
||||
plugins:
|
||||
- faker
|
||||
|
||||
POST /anything:
|
||||
alias: anything
|
||||
fakeIt: true
|
||||
payload:
|
||||
name:
|
||||
first: '{{name.firstName}}'
|
||||
last: '{{name.lastName}}'
|
||||
|
||||
address: '{{address.city}}, {{address.state}}'
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
const Faker = require('faker');
|
||||
|
||||
class BeauFaker {
|
||||
constructor(registry, settings = {}) {
|
||||
registry.addPreRequestModifier(this.fakeItTillYouMakeIt.bind(this));
|
||||
}
|
||||
|
||||
fakeItTillYouMakeIt(request, orig) {
|
||||
if (!orig.FAKEIT) return request;
|
||||
|
||||
this.fakeIt(request.body);
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
fakeIt(body) {
|
||||
Object.keys(body).forEach(key => {
|
||||
if (typeof body[key] === 'string') {
|
||||
body[key] = Faker.fake(body[key]);
|
||||
} else if (typeof body[key] === 'object') {
|
||||
this.fakeIt(body[key]);
|
||||
}
|
||||
});
|
||||
|
||||
return body;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BeauFaker;
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"name": "beau-faker",
|
||||
"version": "0.0.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"faker": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/faker/-/faker-4.1.0.tgz",
|
||||
"integrity": "sha1-HkW7vsxndLPBlfrSg1EJxtdIzD8="
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"name": "beau-faker",
|
||||
"version": "0.0.1",
|
||||
"description": "A Faker.js plugin for Beau",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Seich/beau-faker.git"
|
||||
},
|
||||
"keywords": [
|
||||
"beau"
|
||||
],
|
||||
"author": "David Diaz",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/Seich/beau-faker/issues"
|
||||
},
|
||||
"homepage": "https://github.com/Seich/beau-faker#readme",
|
||||
"dependencies": {
|
||||
"faker": "^4.1.0"
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue