Skip to content

Commit

Permalink
core: added combination support
Browse files Browse the repository at this point in the history
- tests updated
- documentation
- package bump

Impact: low
  • Loading branch information
indieisaconcept committed Jul 26, 2014
1 parent 315ce57 commit 368d43c
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 5 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ var fixturl = require('fixturl'),
```
> Example invocation
### Combinations

Should you wish to generation multiple combinations for a url this is possible by specifying an array for either params for query.

```javascript
fixturl('/some/path/:id', {
param: [
{ id: '12345' },
{ id: '6789' }
],
query: [
{ foo: 'bar' },
{ foo: 'bar', buzz: 'fizz' }
]
});
```
> Example of url combinations
`fixturl` will return an array containing generated fixtures. For convenience the following additional Array methods are made available.

Behind the scenes `fixturl` uses [reverend](reverend-url) to support express like route parameter subsitution.
Expand All @@ -51,6 +69,7 @@ fixtures.random(); // Returns a random item in the array.

## Release History

- **0.1.1** Support for combined configs
- **0.1.0** Initial release

## License
Expand Down
16 changes: 12 additions & 4 deletions lib/fixturl.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@ module.exports = function (/* String */ path, /* Object */ config) {

config.forEach(function (con) {

var url = reverend(path, con.param || {}),
query = con.query || {};

fixtures.push(URI(url).query(query).toString());
var params = con.param || {},
query = con.query || {};

params = Array.isArray(params) ? params : [params];
query = Array.isArray(query) ? query : [query];

params.forEach(function (param) {
var url = reverend(path, param);
query.forEach(function (qry) {
fixtures.push(URI(url).query(qry).toString());
});
});

});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fixturl",
"version": "0.1.0",
"version": "0.1.1",
"description": "Pattern based fixture generator for urls",
"main": "index.js",
"scripts": {
Expand Down
45 changes: 45 additions & 0 deletions test/fixturl_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,49 @@ describe('fixturl', function() {

});

it('generates a multiple url fixtures from a combined config ( param & query array )', function () {

var result = fixturl('/some/path/:id', {
param: [
{ id: '12345' },
{ id: '6789' }
],
query: [
{ foo: 'bar' },
{ foo: 'bar', buzz: 'fizz' }
]
});

expect(result.length).to.eql(4);

['/some/path/12345?foo=bar',
'/some/path/12345?foo=bar&buzz=fizz',
'/some/path/6789?foo=bar',
'/some/path/6789?foo=bar&buzz=fizz'].forEach(function (url) {
return expect(result.indexOf(url) !== -1).to.be.true;
});

});

it('generates a multiple url fixtures from a combined config ( single array )', function () {

var result = fixturl('/some/path/:id', {
param: [
{ id: '12345' },
{ id: '6789' }
],
query: {
foo: 'bar'
}
});

expect(result.length).to.eql(2);

['/some/path/12345?foo=bar',
'/some/path/6789?foo=bar'].forEach(function (url) {
return expect(result.indexOf(url) !== -1).to.be.true;
});

});

});

0 comments on commit 368d43c

Please sign in to comment.