Comparing version 0.3.1 to 0.3.2
@@ -30,8 +30,13 @@ { | ||
}, | ||
"var/:id": { | ||
"nested/ace2": { | ||
"mockFile": "ace.json", | ||
"verbs": ["post", "get"], | ||
"switch": ["customerId","multitest"] | ||
}, | ||
"var/:id/:color": { | ||
"mockFile": "xml/queen.xml", | ||
"verbs": ["all"], | ||
"switch": "id" | ||
"switch": ["id", "color"] | ||
} | ||
} | ||
} |
@@ -198,9 +198,20 @@ var express = require('express'), | ||
mockFileParts, mockFilePrefix = "", mockFileBaseName; | ||
if (req.body[options.switch]) { // json post request | ||
switchValue = req.body[options.switch]; | ||
} else if (req.param(options.switch)) { // query param in get request | ||
switchValue = req.param(options.switch); | ||
} else { | ||
var switches = options.switch; | ||
if(!(switches instanceof Array)){ | ||
switches = [switches]; | ||
} | ||
switches.forEach(function(elem){ | ||
if (req.body[elem]) { // json post request | ||
switchValue = switchValue + elem + encodeURIComponent(req.body[elem]); | ||
} else if (req.param(elem)) { // query param in get request | ||
switchValue = switchValue + elem + encodeURIComponent(req.param(elem)); | ||
} | ||
}); | ||
if(!switchValue){ | ||
return; | ||
} | ||
mockFileParts = options.mockFile.split("/"); | ||
@@ -211,3 +222,3 @@ mockFileBaseName = mockFileParts.pop(); | ||
} | ||
options.mockFile = mockFilePrefix + options.switch + encodeURIComponent(switchValue) + "." + mockFileBaseName; | ||
options.mockFile = mockFilePrefix + switchValue + "." + mockFileBaseName; | ||
}; | ||
@@ -214,0 +225,0 @@ |
{ | ||
"name": "apimocker", | ||
"description": "Simple HTTP server that returns mock service API responses to your front end.", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"engines": { | ||
@@ -6,0 +6,0 @@ "node": ">=0.10.0" |
@@ -85,3 +85,3 @@ # apimocker | ||
}, | ||
"nested/ace": { | ||
"nested/ace": { | ||
"mockFile": "ace.json", | ||
@@ -91,2 +91,7 @@ "verbs": ["post", "get"], | ||
}, | ||
"nested/ace2": { | ||
"mockFile": "ace.json", | ||
"verbs": ["post", "get"], | ||
"switch": ["customerId","multitest"] | ||
}, | ||
"var/:id": { | ||
@@ -118,2 +123,12 @@ "mockFile": "xml/queen.xml", | ||
You can now also define an array of values to switch on. Given the configuration in "ace2", a request to "nested/ace2" containing: | ||
```js | ||
{ | ||
"multitest": "abc", | ||
"customerId": 1234 | ||
} | ||
``` | ||
will return data from the mock file called "customerId1234multitestabc.ace.json". Note that when using multiple switches, the filename must have parameters in the same order as configured in the "switch" setting in config.json. | ||
Also, apimocker will look for the filename that matches ALL the request parameters. If one does not match, then the base file will be returned. | ||
## Runtime configuration | ||
@@ -143,2 +158,4 @@ After starting apimocker, mocks can be configured using a simple http api. | ||
## Versions | ||
### 0.3.2 | ||
Added support for multiple switch parameters on a single URL. Thanks @skjegg and @snyoz ! | ||
### 0.3.1 | ||
@@ -145,0 +162,0 @@ Added support for a static path. (see issue #9) |
@@ -205,2 +205,10 @@ /* global describe, it, beforeEach, afterEach, after */ | ||
}); | ||
it("sets correct mock file path with two switch values", function() { | ||
svcOptions.switch = ["productId", "color"]; | ||
reqStub.body.productId = "345"; | ||
reqStub.body.color = "red"; | ||
mocker.setMockFile(svcOptions, reqStub); | ||
expect(svcOptions.mockFile).to.equal("productId345colorred.base"); | ||
}); | ||
}); | ||
@@ -207,0 +215,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42798
21
873
176