GithubHelp home page GithubHelp logo

seriema / angular-apimock Goto Github PK

View Code? Open in Web Editor NEW
65.0 65.0 9.0 10.05 MB

Automatically route your API calls to static JSON files, for hiccup free front–end development.

Home Page: johansson.jp/angular-apimock

License: MIT License

JavaScript 99.97% HTML 0.03%

angular-apimock's People

Contributors

gitter-badger avatar martinsandstrom avatar seriema avatar ssassi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

angular-apimock's Issues

the ability to return headers in mock requests

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?

Development to Production settings

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

bug or enhancement

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.)

Add tests against different AngularJS versions

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?

mock url

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.

Publishing task is broken

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.

Fix and improve publish task

Issue

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.

screenshot 2015-10-03 14 23 06

Possible solution

grunt-github-releaser and gh-release both look interesting. We're currently using grunt-bump.

Expected result

Access to dry-run for a test run and the Github should look like this.
screenshot 2015-10-03 14 22 56

Timestamps in filepath are invalid

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.

Missing code documentation

@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?

SauceLabs failing on PR's

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.

Install through NPM error

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.

Force mocking

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.

Write contribution guidelines

A lot of projects have a CONTRIBUTING.md file and now that we have some PRs (yay! 😃 ) we should have some guidelines.

Create unit test for the httpInterceptor, multiple cases.

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.

Ability to mock several APIs

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.

Use JSCS for code style checking

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.

Changelogs

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).

Support Angular 1.5

Angular 1.5 is currently in beta. It should be included in the tests as soon as it's out.

Decide on a date format for URL query params

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.

Use original request if the reroute fails

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

Handle queries (i.e. "?name=Pikachu")

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

  • Changes redirect logic so that /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).
  • It will lowercase and URI encode the queries (i.e. Pikaču becomes pika%C4%8Du).
  • It will sort the query params in alphabetical ascending order (i.e. strength=...&name=... becomes name=...&strength=...).

npm page looks broken

The description looks broken. I think it's just grabbing the first X characters from the Readme and then the badges becomes trashed.

See the top, the badges "build passing", "coverage 100%", and then right after it there's broken markdown.
screenshot 2015-10-25 11 23 43

Inconsistent handling of undefined URL params

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.

Test cases

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

Wanted result

= 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.

Increase flexibility in API-url replacement

Currently apiMock simply does a string.replace to change apiPath into mockDataPath.

Two other options could be added:

  1. Use a regex for apiPath.
  2. Use a method for mockDataPath.

Testing directives with templateUrl returns blank templates

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">'.

Drop IE8 support

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:

  • Trailing commas: Change JSCS config from disallowTrailingComma to requireTrailingComma with ignoreSingleLine and ignoreSingleValue.
  • Pollyfills: Remove code with TODO: IE8:
  • SauceLabs: Remove SL_IE_8 from karma.conf.js and Gruntfile.js
  • Angular: Remove 1.2 from Gruntfile.js and update bower.json to ^1.3.0

add delay configuration

Hi,

Would be nice to add delay configuration.
(make the mock data returning closer to reality, see some spinners, etc.)

Use $httpBackend service in unit tests with apiMock

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.