Skip to content

Commit

Permalink
fix bug with set number for query param in config
Browse files Browse the repository at this point in the history
  • Loading branch information
DudaGod committed Sep 30, 2016
1 parent fe2fb92 commit 89cabe2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ module.exports = {
};
```

To pass additional url parameters you can use environment variables,
which should start with `HERMIONE_URL_` or specify them in the `hermione` config file.
To pass additional url parameters you can use environment variables, which should start with `HERMIONE_URL_` or specify them in the `hermione` config file.

For example, you have the following test url: `http://localhost/test/?name=hermione` and
you want to add query parameter via environment variable:
For example, you have the following test url: `http://localhost/test/?name=hermione` and you want to add query parameter via environment variable:

```bash
HERMIONE_URL_QUERY_TEXT=ololo hermione
Expand Down Expand Up @@ -72,7 +70,7 @@ Note: environment variables have higher priority than config values.

In previous example you have seen how add url parameters. Now we look how to concat and override url parameters.

Suppose, you want to add query parameter `name` which is already present in your test url: `http://localhost/test/?name=hermione` and you don't want to override it:
Suppose, you want to add query parameter `name` which is already presented in your test url: `http://localhost/test/?name=hermione` and you don't want to override it:

```js
'hermione-url-decorator': {
Expand Down
4 changes: 3 additions & 1 deletion lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
const url = require('url');
const _ = require('lodash');

const omitEmptyQueryParams = (query) => _.omitBy(query, (queryParam) => _.isEmpty(queryParam.value));
const omitEmptyQueryParams = (query) => _.omitBy(query, (queryParam) => {
return !_.isNumber(queryParam.value) && _.isEmpty(queryParam.value);
});

const concatValues = (currValue, srcValue, concat) => {
return concat !== false && currValue
Expand Down
11 changes: 11 additions & 0 deletions test/lib/url-decorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ describe('url-decorator', () => {
assert.calledWith(baseUrlFn, '/?text=text&text=foo');
});

it('should concat parameters specified as number', () => {
const browser = mkBrowser();
const baseUrlFn = browser.url;

decorateUrl(browser, {query: {text: {value: 15}}});
browser.url('/?text=text');

assert.calledOn(baseUrlFn, browser);
assert.calledWith(baseUrlFn, '/?text=text&text=15');
});

it('should concat each parameters from array of values', () => {
const browser = mkBrowser();
const baseUrlFn = browser.url;
Expand Down

0 comments on commit 89cabe2

Please sign in to comment.