Skip to content

Instantly share code, notes, and snippets.

@hellsan631
Created February 5, 2018 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hellsan631/fe9d449d9a662a0f5d715dd8e89b617c to your computer and use it in GitHub Desktop.
Save hellsan631/fe9d449d9a662a0f5d715dd8e89b617c to your computer and use it in GitHub Desktop.

Server E2E Mocking Proposal

Rules:

  • 1: All external online API's should be wrapped into our own services.
    • This provides a general guideline for developers when they make calls to a said service
    • We avoid issues if a service changes their api somewhere, as tests would fail.
  • 2: Services should have 100% static methods.
    • API State should be maintained only on the external side of things.
    • This avoids use of any global state making things more predictable and reproducable.
  • 3: Any Calls to API should be mapped/wrapped to methods
    • Reduces copy-paste of the same api calls.
    • Fields&params can be mapped to properties just as easily as they are with an api call.
    • Private methods can be used in a service to wrap things (in javascript, its an underscore)
    • Forces decoupling and smaller functions by moving complex queries to their own functions
  • 4: Services should be tested
    • Make sure all service methods return valid data given tested keys.
    • Also maintains that each service is hooked up to a test environment.
  • 5: Anything that impliments a Service should be tested with a MockService
    • Makes things much more reproduceable, state is static
    • Faster, doesn't have to connect to an external db
    • Better for the environment, uses less electricty

How To Impliment?

https://github.com/theKashey/rewiremock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment