Skip to content

Commit

Permalink
feat(queryParams): lowercase query params
Browse files Browse the repository at this point in the history
Ref #23
  • Loading branch information
seriema committed Aug 6, 2015
1 parent fd17b98 commit 2aeb262
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
17 changes: 9 additions & 8 deletions app/scripts/angular-apimock.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,17 @@ angular.module('apiMock', [])
// Helper methods
//

function serialize(obj) {
obj = sortObjPropertiesAlpha(obj);

var str = [];
angular.forEach(obj, function(value, p) {
var encodedValue = encodeURIComponent(value);
str.push(encodeURIComponent(p) + '=' + encodedValue);
function serialize(paramObj) {
paramObj = sortObjPropertiesAlpha(paramObj);

var keys = Object.keys(paramObj);
var paramArray = keys.map(function(key) {
var encodedValue = encodeURIComponent(paramObj[key].toLowerCase());
var encodedKey = encodeURIComponent(key.toLowerCase());
return encodedKey + '=' + encodedValue;
});

return str.join('&');
return paramArray.join('&');
}

function queryStringToObject(url) {
Expand Down
6 changes: 6 additions & 0 deletions test/spec/services/angular-apimock.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,12 @@ describe('Service: apiMock', function () {
defaultExpectPath = '/mock_data/pokemon/lang=sl&name=pika%C4%8Du.get.json';
expectHttpSuccess();
});

it('should lowercase characters in query params', function () {
defaultRequest.url = '/api/pokemon?NAME=PIKACHU';
defaultExpectPath = '/mock_data/pokemon/name=pikachu.get.json';
expectHttpSuccess();
});
});
});

Expand Down

0 comments on commit 2aeb262

Please sign in to comment.