npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

api-mock-objects

v1.0.5

Published

This repository will hold the happy-path input objects for eaze api endpoints. Each endpoint will have its own json file of working input params that can be pulled in by the index.js service or cli. Pass it the path and request-type of an endpoint and it

Downloads

4

Readme

API Mock Objects

This repository will hold the happy-path input objects for eaze api endpoints. Each endpoint will have its own json file of working input params that can be pulled in by the index.js service or cli. Pass it the path and request-type of an endpoint and it will return an object of path, query and body/post parameters (by command line passing "RUN_ENDPOINT" will also return the response). For endpoints that require data from other endpoints, a "parent" can be assigned, to chain requests together. Wrap any variable-name/key in brackets and the path/request-type of the parent endpoint, and the script will pull values from that endpoint's parent endpoint. For instance, to place an item in a cart, the parent endpoint might be a create-cart endpoint, which also has a parent of a logged-in user; so it would execute that request before generating the mock data necessary to add an item into a cart.

Testing Strategy

Dependencies / Related Repos

Set up

npm install --save-dev https://github.com/eaze/api-mock-objects.git

Usage (script)

const mock = require('api-mock-objects')
mock('auth/signin', 'post').then(function (mockData) {
  console.log(mockData)
})

Usage (cli)

 # Return a sign-in happy-path object, that can be used directly in api-request functions
 GETMOCK_ENDPOINT="auth/signin" GETMOCK_TYPE="post" DEUBG_LEVEL=INFO node index.js

 # Return a sign-in happy-path object, and return the response from api-request
 RUN_ENDPOINT=TRUE GETMOCK_ENDPOINT="auth/signin" GETMOCK_TYPE="post" DEUBG_LEVEL=INFO node index.js

Sample Mock Objects

# Get Location (requires zipCode and xAuthToken from get-user endpoint response)
{
  "headers": {
    "X-Auth-Token": "{xAuthToken}"
  },
  "parent": {
  	"path": "users/{user}/basic",
  	"requestType": "get"
  },
  "path": {},
  "query": {
    "query": "{zipCode}"
  },
  "body": {}
}


# Get User (requires userId and xAuthToken from sign-in endpoint response)
{
  "headers": {
    "X-Auth-Token": "{xAuthToken}"
  },
  "parent": {
  	"path": "auth/signin",
  	"requestType": "post"
  },
  "path": {
    "user": "{userId}" 
  },
  "query": {},
  "body": {}
}


# Sign In
{
  "headers": {},
  "parent": {},
  "path": {},
  "query": {},
  "body": {
    "email": "[email protected]",
    "password": "password"
  }
}

More Ideas:

  • Generate a hierarchical graph of the parent/child relationship of each endpoint. https://bl.ocks.org/mbostock/4063550

  • There could be a "cleanup" parameter that could indicate an endpoint necessary to remove anything created in the process of creating the mock data. Those endpoints could be held back until all tests are run.

  • The generated api-request test should be run hierarchically so that no endpoint is tested before it's parent is tested.

  • The mock-data test could iterate through each mock object using JOI to verify the successful responses and handle error/edge cases.

  • It would be nice to add the concept of randomizing a parameter to handle those endpoints (with no parents) that cannot be run multiple times with the same data, like /auth/signup.

    const num = (() => { let num = Math.round(Math.random() * 10000000) return 555${Date.now().toString().substr(-7)} })()