commit a69cacdf5ecec93494825269e90b387759d2e495 Author: David Diaz Date: Wed May 16 18:48:23 2018 -0600 Intial commit. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..e6bb537 --- /dev/null +++ b/.prettierrc @@ -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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..4204261 --- /dev/null +++ b/README.md @@ -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. diff --git a/examples/beau.yml b/examples/beau.yml new file mode 100644 index 0000000..8257fd0 --- /dev/null +++ b/examples/beau.yml @@ -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}}' diff --git a/index.js b/index.js new file mode 100644 index 0000000..2daefb8 --- /dev/null +++ b/index.js @@ -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; diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..9140e24 --- /dev/null +++ b/package-lock.json @@ -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=" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..d1ceba1 --- /dev/null +++ b/package.json @@ -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" + } +}