seriema / angular-apimock Goto Github PK
View Code? Open in Web Editor NEWAutomatically route your API calls to static JSON files, for hiccup free front–end development.
Home Page: johansson.jp/angular-apimock
License: MIT License
Automatically route your API calls to static JSON files, for hiccup free front–end development.
Home Page: johansson.jp/angular-apimock
License: MIT License
We have a feature where we make a queue request and it returns a header providing the location of the progress endpoint. This endpoint returns another header with the results endpoint once the processing is completed.
We need the ability to assign those headers to allow our apimock functionality to work again. Would this be possible?
I've installed the mocks without a hitch, great work on the library.
I'm just wondering if there is a way I can remove any trace of angular-apimock for production/distribution.
Either setting $http config 'apiMocks: false' globally or removing entirely without having to go through each $http manually before building distribution. I would also like to remove the script tag injected into the index.html
Is this possible?
Using: Yeoman, generator-angular, grunt, app/ --> dist/
Thanks
I am unable to get this API to work for more than 1 request. Will the config below with multiple routes work?
.config(function (apiMockProvider) {
apiMockProvider.config({
mockDataPath: '/my_mock_data_path1',
apiPath: '/my_api_path1',
apiMock: 'true'
},
{
mockDataPath: '/my_mock_data_path2',
apiPath: '/my_api_path2',
apiMock: 'true'
},
{
mockDataPath: '/my_mock_data_path3',
apiPath: '/my_api_path3',
apiMock: 'true'
});
})
(I would love to be able to chain my all mock route in the config and also able to set all my flags in config.)
Currently only Angular 1.2.15 is used in testing. I have a suspicion (#14) that 1.2.26 might not work with apiMock
, but 1.3.0 will work.
Not sure how to set up the tests so it tests a bunch of different versions. Currently Karma is configured to go directly on the JS files and maybe the easiest way to solve loading/unloading different Angular versions is probably using HTML-files.
Anyone that can help with this?
Make the function, which decides whether to apply mocking, configurable
a la
.config({
mockDataPath: '/mock_data',
apiPath: '/api',
doMock: function(){
var myresult = /* implement some custom check */;
return myresult;
}
});
the default should be the "old" behaviour
Is it it possible to add an option to configure url for mock data requests.
Lets say that we have following real REST urls :
"http://mydomain.com/api/somting" - a list of something
"http://mydomain.com/api/somting/5" - an item
then mocked path's for them will be :
"http://mydomain.com/mock_data/somting.get.json"
"http://mydomain.com/mock_data/somting/5.get.json"
From my point of view it will be more clean to have all mock data for an entity in the same directory:
"http://mydomain.com/mock_data/somting/get.json" - a mocked list of something
"http://mydomain.com/mock_data/somting/5.get.json" - - a mocked item
Would be very appreciate you if you add such option.
The publish task (grunt publish
) never completes successfully.
Running "npm-publish" task
Warning: Dirty workspace, cannot push to NPM.
?? nuget/Angular-ApiMock.0.3.1.nupkg
Use --force to continue.
Aborted due to warnings.
Need to add the newly created nuget file to git, before it can be commited by grunt bump-commit
. Then the grunt npm-publish
task should work.
Make a proper Github release and make sure tagging, nuget, npm, bower, and everything else works. They sometimes fail, but even when that's fixed the release history in Github is boring.
grunt-github-releaser and gh-release both look interesting. We're currently using grunt-bump.
Access to dry-run
for a test run and the Github should look like this.
By using the default implementation for Datetime toString in #51 it's now putting :
in the filename, e.g. releasedate=1996-02-27t00:00:00.000z.get.json
. Which is an invalid filename on Windows, Linux, and OSX.
I'm mostly curious on Docker so I'd like to test it out. Is there a point in using it for a node project or not?
Travis docs: http://docs.travis-ci.com/user/docker/
@seriema great advance in the code, congratulation!
I like to be in the same page with you, and advance with the team!
Now it's difficult understand what thats each methods because no documentation in the code.
It's possible to add?
Currently at 97%. Want to try to get it to 100%.
Go through this properly and decide on a course of action (if needed):
https://code.angularjs.org/1.2.26/docs/api/ng/service/$http#response-interceptors-deprecated-
This happened when PR #29 triggered a build that failed. Seems to be user account related:
L838: You used username 'None' and access key 'None' to authenticate, which are not valid Sauce Labs credentials.
The subsequent build by me worked, so I guess it's on PR's from other users accounts. Even though it's triggered by Travis which has credentials.
I've tried to install through NPM and I'm getting this error:
ENOENT No bower.json present
npm WARN EPACKAGEJSON [email protected] No repository field.
npm WARN EPACKAGEJSON [email protected] No license field.
npm ERR! Darwin 14.3.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "angular-apimock" "--save-dev"
npm ERR! node v4.2.2
npm ERR! npm v3.3.9
npm ERR! code ELIFECYCLE
npm ERR! [email protected] postinstall: `bower install`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script 'bower install'.
npm ERR! This is most likely a problem with the angular-apimock package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! bower install
npm ERR! You can get their info via:
npm ERR! npm owner ls angular-apimock
npm ERR! There is likely additional logging output above.
It works as expected with Bower.
Travis is showing this notice on current builds:
This job ran on our legacy infrastructure. Please read our docs on how to upgrade
It's simple to upgrade, but I'd also like to investigate the caching possibilities now available for open source projects.
First of all, great work and thank you very much for doing this!
Would be nice to add a global activation parameter in config.
something like :
apiMockProvider.config({
mockDataPath: 'tests/',
apiPath: 'api/',
forceEnabled : true; // force to serve mocks
});
In this way i can define a context to serve mocks for all requests (e.g: development) and easily restore normal api responses when i switch to production/staging.
A lot of projects have a CONTRIBUTING.md
file and now that we have some PRs (yay! 😃 ) we should have some guidelines.
Hi,
Possible to add to the module the installation via bower
http://bower.io/
https://nodesecurity.io/ is a nice initiative that warns when security issues are found in npm packages.
Not really necessary, since no nodejs code makes it into the library so no users are actually affected. But I'd enjoy the security sanity check locally anyway.
https://nodesecurity.io/tools
https://www.npmjs.com/package/grunt-nsp-package
Describe for the httpInterceptor, the unit test for different URL and Methods, also compatibility of work with other interceptors or external data services like firebase, simperium, parse, etc.
Example:
GET, http://server/api/test
POST, http://server/api/test/new
DELETE, http://production.firebase.io/api/test/1
PUT, http://server/api/test/4
GET, /api/test
GET, /test
My specific case, i have a http interceptor that include the base server uri. This need compatibility.
Thanks for this, I really do love what it does!
I have forked the repo to perhaps work on this but we have a need for the library to be able to mock out several APIs instead of just one.
As part of #22 we should have automatic checking of code style to avoid commits with changes to white space or other unnecessary changes, but also help enforce a consistent coding style.
A Changelog file would be nice, and comments on the release tags.
Looking at how to do this automatically with Grunt on dist
task (when version is bumped).
As suggested by @ceoaliongroo, allow individual calls to be mocked.
Example call:
$http({
method: 'GET',
url: 'http:/server/people',
apiMock: true //
})
As suggested by @ceoaliongroo. This would allow WebStorm to run a plugin and work on most peoples computers with Grunt, and keep Travis-CI working (needs a line in the travis config though I think).
Angular 1.5 is currently in beta. It should be included in the tests as soon as it's out.
While working on #44 I added a test case for dates, and the expected file name becomes so long. 1996-01-27
becomes the ISO string 1996-02-27t00:00:00.000z
. E.g. a potential file name would be /mock_data/pokemon/releasedate=1996-02-27t00:00:00.000z.get.json
.
Question 1: How short is ok? YYYY-MM-DD or YY-MM-DD? With or without time of day? How short timestamp? HH-MM-SS is enough?
Question 2: Should it be easy to override somehow? I'm thinking about scenarios in search API's or similar where the dates can change and would require multiple .json
files to match. Maybe the date doesn't have a real impact on the UI design, like just outputting the date. But I can also think of scenarios where it does matter, like changing texts or colors depending on the date value.
Hi ,
Is there a way to configure angular-apimock to use the original request if the reroute fails. I believe in the current implementation its possible to do the opposite (i.e try the original request, if it fails then it tries to recover with a reroute) by setting apimock=auto.
Thanks & Regards
Seems like only http://johansson.jp/angular-apimock/#/demo-simple?apimock=true works. So http://johansson.jp/angular-apimock/#/demo-simple?apimock=auto and other commands aren't working.
The unit tests aren't picking it up, but I think it's because I'm not testing all commands with $location.search('apimock', x);
.
Currently query parameters in the API URL are just stripped out. There should be an optional setting for including them in the redirect.
Use case
Better testing of search-like features where one could test search terms that will give different search results, such as no results, a few results, a lot of results, spelling suggestions, etc.
Usage
Config set in the config()
by setting stripQueries
to false
(default is true
). Sample:
angular.module('testApp', ['apiMock'])
.config(function (apiMockProvider) {
apiMockProvider.config({
stripQueries: false
});
});
Descoped (do this later as a separate feature):
Local and global flag set on individual requests, which would be perfect for isolated testing of a autocompletion type search. To not pollute the $http
config we should scope it within apiMock
, but that requires another feature (to allow config objects instead of just true/false
). Sample:
app.service('exampleService', function ($http) {
// ...
$http({
method: 'GET',
url: '...',
apiMock: {
stripQueries: true
}
}) // ...
// ...
});
Effect
/api/pokemon?name=Pikachu
no longer strips the query and redirects to /mock_data/pokemon.get.json
. Instead it redirects to /mock_data/pokemon/name=pikachu.get.json
(similar to #13 where /api/pokemon
would redirect to /mock_data/pokemon/get.json
instead of /mock_data/pokemon.get.json
, but for now we only do this for URL's with queries).Pikaču
becomes pika%C4%8Du
).strength=...&name=...
becomes name=...&strength=...
).There are some benefits If use the module use $location instead window.location
http://docs.angularjs.org/guide/$location
While working on #44 I noticed we weren't testing "date in URL query param" properly so we didn't see that it never worked on IE8.
Travis build failure with SauceLabs on IE8: https://travis-ci.org/seriema/angular-apimock/builds/86030580
Related: #50
While working on #44 to raise test-coverage I noticed that empty URL params were handled differently depending on if it's an undefined property on the $http
config object, or if it's just an empty value in the URL.
Case 1: empty value in URL
defaultRequest.url = '/api/pokemon?releaseDate';
becomes
/mock_data/pokemon/releasedate=.get.json
.
Case 2: undefined value in object
defaultRequest.url = '/api/pokemon';
defaultRequest.params = {
'releaseDate': undefined
};
becomes
/mock_data/pokemon/releasedate=undefined.get.json
=
and =undefined
are both unwanted in a file name IMHO. So it should be completely removed. I.e. expected file path would be /mock_data/pokemon/releasedate.get.json
.
Currently apiMock
simply does a string.replace
to change apiPath
into mockDataPath
.
Two other options could be added:
apiPath
.mockDataPath
.Could you consider to add a main
field in package.json in order to use require('angular-apimock)
instead of require('angular-apimock/dist/angular-apimock.js')
?
I have a few directives with templateUrl
and when I add this module tests stop working me.
PhantomJS 1.9.8 (Mac OS X 0.0.0) Unit testing login process Should contains the login form FAILED
Expected '' to contain '<form name="loginForm" ng-submit="ctrl.onSubmit()" novalidate="" class="ng-pristine ng-invalid ng-invalid-required">'.
It's causing more and more hacks. The biggest change for AngularJS support will be that version 1.2
will be dropped, as they dropped IE8 support in 1.3
.
Here's a checklist of things to change in the source once the IE8 support gets dropped:
disallowTrailingComma
to requireTrailingComma
with ignoreSingleLine
and ignoreSingleValue
.TODO: IE8:
SL_IE_8
from karma.conf.js
and Gruntfile.js
Gruntfile.js
and update bower.json
to ^1.3.0
Try not to go crazy with everything on http://shields.io but see what can be changed or added if it makes sense.
Since nuget/npm/bower links are in the readme text, then maybe badges for them could make sense.
Hi,
Would be nice to add delay configuration.
(make the mock data returning closer to reality, see some spinners, etc.)
We have Bower support but I would like NuGet support too.
Your package is really helpful. Thank you guys.
I my old unit tests i am using $httpBackend with .whenGET mocks.
beforeEach(() => {
inject(function ($injector, _$compile_, _$rootScope_) {
// The injector unwraps the underscores (_) from around the parameter names when matching
$compile = _$compile_;
$rootScope = _$rootScope_;
$httpBackend = $injector.get("$httpBackend");
});
$httpBackend.whenGET("api/langs/gb.json").respond({ "COMMON.HOME": homeName });
$httpBackend.whenGET("api/langs/de.json").respond({});
$httpBackend.whenGET(/^private\/auth\?.*/).respond({});
directiveElem = getCompiledElement();
});
Now i have included apiMock and my unit tests doesn't work any more.
it("should be defined and contiain first list item for home.", function () {
$httpBackend.flush();
expect(directiveElem).toBeDefined();
let olElement = directiveElem.find("ol");
expect(olElement).toBeDefined();
let homeElement = directiveElem.find("li");
expect(homeElement.html()).toContain(homeName);
});
I have tried
apiMockProvider.config({
disable: true
});
but it didn't help.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.