Skip to content

Commit 295efd9

Browse files
committed
chore(release): release v0.3.0. See CHANGELOG.md
1 parent aa32433 commit 295efd9

File tree

5 files changed

+66
-16
lines changed

5 files changed

+66
-16
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
<a name="0.3.0"></a>
2+
# [0.3.0](https://github.com/seriema/angular-apimock/compare/v0.2.1...v0.3.0) (2015-10-05)
3+
4+
5+
### Bug Fixes
6+
7+
* **grunt:** revert failed merge ([7df9420](https://github.com/seriema/angular-apimock/commit/7df9420))
8+
9+
### Features
10+
11+
* **apiMock:** default mock setting ([f4e2258](https://github.com/seriema/angular-apimock/commit/f4e2258)), closes [#24](https://github.com/seriema/angular-apimock/issues/24)
12+
* **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)
13+
* **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)
14+
15+
16+
117
<a name="0.2.1"></a>
218
## [0.2.1](https://github.com/seriema/angular-apimock/compare/v0.2.0...v0.2.1) (2015-09-13)
319

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-apimock",
3-
"version": "0.2.1",
3+
"version": "0.3.0",
44
"main": "dist/angular-apimock.min.js",
55
"appPath": "app",
66
"ignore": [

dist/angular-apimock.js

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! Angular API Mock v0.2.1
1+
/*! Angular API Mock v0.3.0
22
* Licensed with MIT
33
* Made with ♥ from Seriema + Redhorn */
44
/* Create the main module, `apiMock`. It's the one that needs to be included in
@@ -46,11 +46,12 @@ angular.module('apiMock', [])
4646
var $log;
4747
var $q;
4848
var config = {
49+
defaultMock: false,
4950
mockDataPath: '/mock_data',
5051
apiPath: '/api',
5152
disable: false,
5253
stripQueries: true,
53-
delay: 0,
54+
delay: 0
5455
};
5556
var fallbacks = [];
5657

@@ -112,11 +113,11 @@ angular.module('apiMock', [])
112113
}
113114

114115
if (angular.isArray(toSerialize)) {
115-
angular.forEach(toSerialize, function(value, index) {
116+
angular.forEach(toSerialize, function (value, index) {
116117
serialize(value, prefix + '[' + (angular.isObject(value) ? index : '') + ']');
117118
});
118119
} else if (angular.isObject(toSerialize) && !angular.isDate(toSerialize)) {
119-
forEachSorted(toSerialize, function(value, key) {
120+
forEachSorted(toSerialize, function (value, key) {
120121
serialize(value, prefix +
121122
(topLevel ? '' : '[') +
122123
key +
@@ -139,7 +140,7 @@ angular.module('apiMock', [])
139140
var paramArray = paramString.split('&');
140141

141142
var result = {};
142-
angular.forEach(paramArray, function(param) {
143+
angular.forEach(paramArray, function (param) {
143144
param = param.split('=');
144145
result[param[0]] = param[1] || '';
145146
});
@@ -166,9 +167,13 @@ angular.module('apiMock', [])
166167

167168
function getParameter(req) {
168169
var mockValue = localMock(req);
170+
// Note: `false` is a valid option, so we can't use falsy-checks.
169171
if (mockValue === undefined) {
170172
mockValue = globalMock();
171173
}
174+
if (mockValue === undefined) {
175+
mockValue = config.defaultMock;
176+
}
172177

173178
return mockValue;
174179
}
@@ -209,7 +214,33 @@ angular.module('apiMock', [])
209214
}
210215

211216
function isApiPath(url) {
212-
return url.indexOf(config.apiPath) === 0;
217+
return (apiPathMatched(url, config.apiPath) !== undefined);
218+
}
219+
220+
function apiPathMatched(url, apiPath) {
221+
var match; // Lets initially assume undefined as no match
222+
223+
if (angular.isArray(apiPath)) {
224+
angular.forEach(apiPath, function (path) {
225+
if (match) { return; } // Hack to skip more recursive calls if already matched
226+
var found = apiPathMatched(url, path);
227+
if (found) {
228+
match = found;
229+
}
230+
});
231+
}
232+
if (match) {
233+
return match;
234+
}
235+
if (apiPath instanceof RegExp) {
236+
if (apiPath.test(url)) {
237+
return apiPath;
238+
}
239+
}
240+
if ((url.toString().indexOf(apiPath) === 0)) {
241+
return apiPath;
242+
}
243+
return match;
213244
}
214245

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

238269
// replace apiPath with mockDataPath.
239270
var oldPath = req.url;
240-
var redirectedPath = req.url.replace(config.apiPath, config.mockDataPath);
271+
272+
var redirectedPath = req.url.replace(apiPathMatched(req.url, config.apiPath), config.mockDataPath);
241273

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

246278
// query strings are stripped by default (like ?search=banana).
247279
if (!config.stripQueries) {
280+
248281
//test if we have query params
249282
//if we do merge them on to the params object
250283
var queryParamsFromUrl = queryStringToObject(queries);
251284
var params = angular.extend(req.params || {}, queryParamsFromUrl);
252285

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

@@ -357,7 +390,7 @@ angular.module('apiMock', [])
357390
}];
358391
})
359392

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

375408
$timeout(
376-
function() {
377-
deferred.resolve( apiMock.onResponse(res) ); // TODO: Apparently, no tests break regardless what this resolves to. Fix the tests!
409+
function () {
410+
// TODO: Apparently, no tests break regardless what this resolves to. Fix the tests!
411+
deferred.resolve(apiMock.onResponse(res));
378412
},
379413
apiMock.getDelay(),
380414
true // Trigger a $digest.
@@ -396,7 +430,7 @@ angular.module('apiMock', [])
396430
deferred.resolve(data);
397431
});
398432
} else {
399-
deferred.reject( rej );
433+
deferred.reject(rej);
400434
}
401435
},
402436
apiMock.getDelay(),

dist/angular-apimock.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-apimock",
3-
"version": "0.2.1",
3+
"version": "0.3.0",
44
"author": "John-Philip Johansson <seriema@gmail.com> (http://johansson.jp/)",
55
"homepage": "http://johansson.jp/angular-apimock/",
66
"bugs": "https://github.com/seriema/angular-apimock/issues",

0 commit comments

Comments
 (0)