2.0.2 • Published 4 years ago
mock-ff v2.0.2
Mock For Frontend
This package aim to help the frontend development by providing a wrapper over mockserver package.
Expectations
You just gonna need to create a new folder to store your expectations, for more info in how to create expectations you can find here and here
Sample
// ./expectations/login.json
[
{
"httpRequest": {
"method": "POST",
"path": "/login"
},
"httpResponse": {
"body": "token"
}
}
]
Or
// ./expectations/js-sample.js
module.exports = (mockClient) => {
mockClient
.mockAnyResponse({
httpRequest: {
method: "GET",
path: "/jssample",
},
httpResponse: {
body: "EXPECTATION LOAD FROM JS FILE",
},
})
.then(
function () {
console.log("expectation created");
},
function (error) {
console.log(error);
}
);
};
PS: The mock server load JSON expectation before JS expectations
How to use
Execute the following command
$ npm i -g mock-ff
$ mock-ff help
$ mock-ff start ./expectations/ -p 7777
$ [optional] mock-ff stop -p 7777
PS: Make sure you have the right permissions to read/write in the folder you are executing the command or mock-ff will fail.
This command will start your mockserver on port 7777
Useful requests
Healthcheck
curl --request POST --url http://localhost:7777/mockserver/healthcheck
Recorded Requests and Responses
curl --request PUT --url 'http://localhost:7777/mockserver/retrieve?type=REQUEST_RESPONSES'
Dependencies
- JDK 11+