New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

faussaire

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

faussaire - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

src/controller.js

2

package.json
{
"name": "faussaire",
"version": "0.1.4",
"version": "0.1.5",
"description": "Lightweight library to mock API for testing purpose",

@@ -5,0 +5,0 @@ "main": "build/faussaire.js",

@@ -1,2 +0,2 @@

# Faussaire
# Faussaire v0.1.5
Lightweight javascript library to mock network request for testing purposes

@@ -30,11 +30,11 @@

```js
import faussaire from 'faussaire';
import faussaire, {Route, Controller, Response} from 'faussaire';
faussaire
.Route({
.route(Route({
template: "http://foo.com",
methods: ["GET"],
controller: {
controller: Controller({
run: (params, options) => {
return faussaire.Response({
return Response({
data: {

@@ -48,4 +48,4 @@ foo: params.foo,

}
}
});
})
}));

@@ -61,14 +61,14 @@ const response = faussaire.fetch("http://foo.com", "GET", {foo: "bar", bar: "qux"});

```js
import faussaire from 'faussaire';
import faussaire, {Route, Controller, Response} from 'faussaire';
faussaire
.Route({
.route(Route({
template: "http://foo.com/ressouce",
methods: ["GET"],
controller: {
controller: Controller({
authenticate: function(params, options){
if(params.apikey){
return {
apikey: params.apikey
at: Date.now()
apikey: params.apikey,
at: Date.now(),
expire: //...

@@ -80,3 +80,3 @@ }

if(options.token){
return faussaire.Response({
return Response({
status: 200,

@@ -92,4 +92,4 @@ statusText: "OK"

}
}
});
})
}));

@@ -104,8 +104,23 @@ const response = faussaire.fetch("http://foo.com", "GET", {foo: "bar", bar: "qux"});

### faussaire.Route: (route) => faussaire
### faussaire.route: (route) => faussaire
Adds a route to Faussaire.
### faussaire.Response: (Object) => Object
### Route: (Object) => Object
Return a route with :
* template : usually a URL or a Regex. If the URL matches the template, the controller starts processing.
* methods : an array of HTTP methods to handle (basically ["GET"])
* controller : a Controller type object processing the request.
#### Controller: (Object) => Object
Return a controller with :
* `run(params, options)`: this function must return a response. The options holds a method entry and might have additionnal
data passed by authenticate for example.
* `authenticate(params, options')`: must return an object representing an authentication token if the request hold
enough information to recognize the user, or return nothing/undefined.
### Response: (Object) => Object
Return a basic HTTP response with :

@@ -155,2 +170,4 @@ * data : the body's response

* Simulate timeout if wanted (you probably don't in testing but might be useful for offline support)
* Get closer to what a network request flow should look alike (in term of headers, etc)
* Get closer to what a network request flow should look alike (in term of headers, etc)
* Add Listeners which look for a certain template and then call subscribers when it happen, and/or pass additional
options to the controller (like Symfony Events Listeners)

@@ -1,11 +0,11 @@

const faussaire = require('../src/faussaire');
import faussaire, {Route, Controller, Response} from '../src/faussaire';
describe('Faussaire should mock API', function(){
faussaire
.Route({
.route(Route({
template: "http://foo.com",
methods: ["GET"],
controller: {
controller: Controller({
run: () => {
return faussaire.Response({
return Response({
data: {},

@@ -16,4 +16,4 @@ status: 200,

}
}
});
})
}));

@@ -20,0 +20,0 @@ it('should fetch data from a correct URL', function(){

@@ -1,2 +0,4 @@

const responseFactory = require('./response');
import responseFactory from './response';
import routeFactory from './route';
import controllerFactory from './controller';

@@ -50,3 +52,3 @@ /**

*/
Route: (route) => {
route: (route) => {
_routes.push(route);

@@ -56,6 +58,2 @@ return faussaire;

Response: (obj) => {
return responseFactory(obj);
},
/**

@@ -105,2 +103,5 @@ * Fetch the data synchronously.

module.exports = createFaussaire();
export default createFaussaire();
export const Route = routeFactory;
export const Controller = controllerFactory;
export const Response = responseFactory;

@@ -10,2 +10,2 @@ const response = (obj) => {

module.exports = response;
export default response;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc