Skip to content

Commit

Permalink
chore(release): release v0.3.0. See CHANGELOG.md
Browse files Browse the repository at this point in the history
  • Loading branch information
seriema committed Oct 5, 2015
1 parent aa32433 commit 295efd9
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 16 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,19 @@
<a name="0.3.0"></a>
# [0.3.0](https://github.com/seriema/angular-apimock/compare/v0.2.1...v0.3.0) (2015-10-05)


### Bug Fixes

* **grunt:** revert failed merge ([7df9420](https://github.com/seriema/angular-apimock/commit/7df9420))

### Features

* **apiMock:** default mock setting ([f4e2258](https://github.com/seriema/angular-apimock/commit/f4e2258)), closes [#24](https://github.com/seriema/angular-apimock/issues/24)
* **apiPath:** add support for arrays and/or regexp when matching ([0a08a7d](https://github.com/seriema/angular-apimock/commit/0a08a7d)), closes [#16](https://github.com/seriema/angular-apimock/issues/16)
* **grunt:** enforce code style with JSCS ([583b65a](https://github.com/seriema/angular-apimock/commit/583b65a)), closes [#30](https://github.com/seriema/angular-apimock/issues/30)



<a name="0.2.1"></a>
## [0.2.1](https://github.com/seriema/angular-apimock/compare/v0.2.0...v0.2.1) (2015-09-13)

Expand Down
2 changes: 1 addition & 1 deletion bower.json
@@ -1,6 +1,6 @@
{
"name": "angular-apimock",
"version": "0.2.1",
"version": "0.3.0",
"main": "dist/angular-apimock.min.js",
"appPath": "app",
"ignore": [
Expand Down
58 changes: 46 additions & 12 deletions dist/angular-apimock.js
@@ -1,4 +1,4 @@
/*! Angular API Mock v0.2.1
/*! Angular API Mock v0.3.0
* Licensed with MIT
* Made with ♥ from Seriema + Redhorn */
/* Create the main module, `apiMock`. It's the one that needs to be included in
Expand Down Expand Up @@ -46,11 +46,12 @@ angular.module('apiMock', [])
var $log;
var $q;
var config = {
defaultMock: false,
mockDataPath: '/mock_data',
apiPath: '/api',
disable: false,
stripQueries: true,
delay: 0,
delay: 0
};
var fallbacks = [];

Expand Down Expand Up @@ -112,11 +113,11 @@ angular.module('apiMock', [])
}

if (angular.isArray(toSerialize)) {
angular.forEach(toSerialize, function(value, index) {
angular.forEach(toSerialize, function (value, index) {
serialize(value, prefix + '[' + (angular.isObject(value) ? index : '') + ']');
});
} else if (angular.isObject(toSerialize) && !angular.isDate(toSerialize)) {
forEachSorted(toSerialize, function(value, key) {
forEachSorted(toSerialize, function (value, key) {
serialize(value, prefix +
(topLevel ? '' : '[') +
key +
Expand All @@ -139,7 +140,7 @@ angular.module('apiMock', [])
var paramArray = paramString.split('&');

var result = {};
angular.forEach(paramArray, function(param) {
angular.forEach(paramArray, function (param) {
param = param.split('=');
result[param[0]] = param[1] || '';
});
Expand All @@ -166,9 +167,13 @@ angular.module('apiMock', [])

function getParameter(req) {
var mockValue = localMock(req);
// Note: `false` is a valid option, so we can't use falsy-checks.
if (mockValue === undefined) {
mockValue = globalMock();
}
if (mockValue === undefined) {
mockValue = config.defaultMock;
}

return mockValue;
}
Expand Down Expand Up @@ -209,7 +214,33 @@ angular.module('apiMock', [])
}

function isApiPath(url) {
return url.indexOf(config.apiPath) === 0;
return (apiPathMatched(url, config.apiPath) !== undefined);
}

function apiPathMatched(url, apiPath) {
var match; // Lets initially assume undefined as no match

if (angular.isArray(apiPath)) {
angular.forEach(apiPath, function (path) {
if (match) { return; } // Hack to skip more recursive calls if already matched
var found = apiPathMatched(url, path);
if (found) {
match = found;
}
});
}
if (match) {
return match;
}
if (apiPath instanceof RegExp) {
if (apiPath.test(url)) {
return apiPath;
}
}
if ((url.toString().indexOf(apiPath) === 0)) {
return apiPath;
}
return match;
}

function prepareFallback(req) {
Expand Down Expand Up @@ -237,21 +268,23 @@ angular.module('apiMock', [])

// replace apiPath with mockDataPath.
var oldPath = req.url;
var redirectedPath = req.url.replace(config.apiPath, config.mockDataPath);

var redirectedPath = req.url.replace(apiPathMatched(req.url, config.apiPath), config.mockDataPath);

var split = redirectedPath.split('?');
var newPath = split[0];
var queries = split[1] || '';

// query strings are stripped by default (like ?search=banana).
if (!config.stripQueries) {

//test if we have query params
//if we do merge them on to the params object
var queryParamsFromUrl = queryStringToObject(queries);
var params = angular.extend(req.params || {}, queryParamsFromUrl);

//test if there is already a trailing /
if (newPath[newPath.length-1] !== '/') {
if (newPath[newPath.length - 1] !== '/') {
newPath += '/';
}

Expand Down Expand Up @@ -357,7 +390,7 @@ angular.module('apiMock', [])
}];
})

.service('httpInterceptor', ['$injector', '$q', '$timeout', 'apiMock', function($injector, $q, $timeout, apiMock) {
.service('httpInterceptor', ['$injector', '$q', '$timeout', 'apiMock', function ($injector, $q, $timeout, apiMock) {
/* The main service. Is jacked in as a interceptor on `$http` so it gets called
* on every http call. This allows us to do our magic. It uses the provider
* `apiMock` to determine if a mock should be done, then do the actual mocking.
Expand All @@ -373,8 +406,9 @@ angular.module('apiMock', [])
var deferred = $q.defer();

$timeout(
function() {
deferred.resolve( apiMock.onResponse(res) ); // TODO: Apparently, no tests break regardless what this resolves to. Fix the tests!
function () {
// TODO: Apparently, no tests break regardless what this resolves to. Fix the tests!
deferred.resolve(apiMock.onResponse(res));
},
apiMock.getDelay(),
true // Trigger a $digest.
Expand All @@ -396,7 +430,7 @@ angular.module('apiMock', [])
deferred.resolve(data);
});
} else {
deferred.reject( rej );
deferred.reject(rej);
}
},
apiMock.getDelay(),
Expand Down
4 changes: 2 additions & 2 deletions dist/angular-apimock.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "angular-apimock",
"version": "0.2.1",
"version": "0.3.0",
"author": "John-Philip Johansson <seriema@gmail.com> (http://johansson.jp/)",
"homepage": "http://johansson.jp/angular-apimock/",
"bugs": "https://github.com/seriema/angular-apimock/issues",
Expand Down

0 comments on commit 295efd9

Please sign in to comment.