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.8 to 0.1.9

74

build/src/faussaire.js

@@ -148,52 +148,48 @@ 'use strict';

*/
fetch: function fetch(url, method, requestBody) {
for (var i = 0; i < _routes.length; i++) {
fetch: function fetch(url, method) {
var requestBody = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
if (!isMatching(_routes[i].template, url)) {
continue;
}
var matchingRoute = _routes.find(function (r) {
return isMatching(r.template, url) && r.methods.indexOf(method.toUpperCase()) > -1;
});
// Checking if the method matches the routes
if (_routes[i].methods.indexOf(method.toUpperCase()) < 0) {
continue;
}
if (!matchingRoute) {
return _onNotFoundError;
}
var query = [],
request = [],
route = extractRouteParameters(_routes[i].template, url);
var query = [],
request = [],
route = extractRouteParameters(matchingRoute.template, url);
// In GET methods, there's no need to read request's body
// If there is a requestBody in the fetch, the user still probably
// Wants them to be considered as query parameters
if (method === "GET") {
query = Object.assign({}, extractURLArgs(url), requestBody);
request = [];
} else {
query = extractURLArgs(url);
request = requestBody;
}
// In GET methods, there's no need to read request's body
// If there is a requestBody in the fetch, the user still probably
// Wants them to be considered as query parameters
if (method === "GET") {
query = Object.assign({}, extractURLArgs(url), requestBody.params);
request = [];
} else {
query = Object.assign({}, extractURLArgs(url), requestBody.params);
request = requestBody.data;
}
var params = {
query: query,
request: request,
route: route
};
var params = {
query: query,
request: request,
route: route
};
// Object holding data about the process
var options = {
method: method
};
// Object holding data about the process
var options = {
method: method
};
if (typeof _routes[i].controller.authenticate === 'function') {
var token = _routes[i].controller.authenticate(params, options);
if (typeof matchingRoute.controller.authenticate === 'function') {
var token = matchingRoute.controller.authenticate(params, options);
if (typeof token !== 'undefined') {
options.token = token;
}
if (typeof token !== 'undefined') {
options.token = token;
}
return _routes[i].controller.run(params, options);
}
return _onNotFoundError;
return matchingRoute.controller.run(params, options);
},

@@ -200,0 +196,0 @@

{
"name": "faussaire",
"version": "0.1.8",
"version": "0.1.9",
"description": "Lightweight library to mock API for testing purpose",

@@ -8,3 +8,3 @@ "main": "build/src/faussaire.js",

"lint": "eslint . && echo 'Lint finished...\n'",
"test": "node tests/index.js",
"test": "jasmine",
"start": "webpack-dev-server --content-base build/",

@@ -11,0 +11,0 @@ "build": "babel src/* --out-dir build",

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

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

@@ -50,3 +50,8 @@

const response = faussaire.fetch("http://foo.com", "GET", {foo: "bar", bar: "qux"});
const response = faussaire.fetch("http://foo.com", "GET", {
params: {
foo: "bar",
bar: "qux"
}
});
```

@@ -118,3 +123,3 @@

return faussaire.Response({
return Response({
status: 403,

@@ -127,3 +132,8 @@ statusText: "Wrong credentials"

const response = faussaire.fetch("http://foo.com", "GET", {foo: "bar", bar: "qux"});
const response = faussaire.fetch("http://foo.com", "GET", {
params: {
foo: "bar",
bar: "qux"
}
});
```

@@ -130,0 +140,0 @@ ## API

@@ -90,4 +90,18 @@ import faussaire, {Route, Controller, Response} from '../src/faussaire';

it('should accept the request having mentionned the apikey in the params', function(){
const response = faussaire.fetch("http://bar.com?titi=toto", "GET", {
params: {
apikey: "azerty"
}
});
expect(response.status).toEqual(200);
});
it('should accept the request having mentionned the apikey in the parameters', function(){
const response = faussaire.fetch("http://bar.com", "GET", {"apikey": "azerty"});
const response = faussaire.fetch("http://bar.com", "GET", {
params: {
apikey: "azerty"
}
});
expect(response.status).toEqual(200);

@@ -97,3 +111,7 @@ });

it('should accept the request having mentionned the apikey in the POST parameters', function(){
const response = faussaire.fetch("http://bar.com", "POST", {"apikey": "azerty"});
const response = faussaire.fetch("http://bar.com", "POST", {
data: {
apikey: "azerty"
}
});
expect(response.status).toEqual(200);

@@ -100,0 +118,0 @@ });

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