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

express-crud-promise-test

v1.2.1

Published

A simple promise-based testing suite for ExpressJS based APIs and [CouchDB](http://couchdb.apache.org/) in the backend. `express-crud-promise-test` relies on [tape](https://www.npmjs.com/package/tape), [supertest](https://www.npmjs.com/package/supertest)

Downloads

14

Readme

Express CRUD Promise Test

A simple promise-based testing suite for ExpressJS based APIs and CouchDB in the backend. express-crud-promise-test relies on tape, supertest, and ramda as its dependencies.

Tests routes that support the following http verbs:

  • POST
  • GET
  • UPDATE (Coming Soon!)
  • DELETE

Getting Started

$ npm install express-crud-promise-test --save-dev

Examples

Test Home Route

Use testGetHome() to verify the home \ route is functioning. Commonly used to ensure the api is available. Accepts an ExpressJS application as its only parameter. Returns a promise containing the HTTP response.

const { testGetHome } = require('express-crud-promise-test')
const app = require('../app.js')
testGetHome(app)
  .then(res => console.log(res))
  .catch(err => console.log(err))

GROUP CRUD TEST

Tests the create, read, update, and delete (CRUD) capabilities on an api route. Use testGroupCRUD() to test GET, POST, PUT, and DELETE HTTP verbs.

testGroupCRUD() accepts the following parameters:

  • app - The ExpressJS application you're testing.
  • testName - The name of your CRUD Test. Example: 'BOOKS CRUD TEST'
  • path - The path/route defined within your ExpressJS route middleware. Example: /books
  • postRequestBody - The resource to add/POST to the database.
  • pk - The CouchDB document primary key (_id) value to equality test after the resource is created in CouchDB. Example: book_brave_new_world. pk value is used for the route value when testing the GET and DELETE for the resource. Example: GET /books/book_brave_new_world

In the example below, the home route is tested followed by CRUD testing the /books and /authors route.

const { testGetHome, testGroupCRUD } = require('express-crud-promise-test')
const app = require('../app.js')

const postRequestBody = {
  title: 'A Brave New World',
  author: 'author_aldous_huxley',
  type: 'book',
  publisher: 'Penguin Books',
  ISBN: '12947281',
  genre: 'Fiction',
  description:
    "Brave New World is a novel written in 1931 by Aldous Huxley, and published in 1932. Set in London in the year AD 2540 (632 A.F.—'After Ford'—in the book), the novel anticipates developments in reproductive technology, sleep-learning, psychological manipulation, and classical conditioning that are combined to make a profound change in society.",
  rating: 95,
  prices: [
    { type: 'paperback', price: 9.99 },
    { type: 'hardback', price: 19.99 },
    { type: 'audio', price: 19.99 },
    { type: 'kindle', price: 12.99 }
  ]
}

const postAuthorRequestBody = {
  name: 'Aldous Huxley',
  placeOfBirth: 'London',
  birthDate: '1932-05-01',
  type: 'author'
}

testGetHome(app)
  .then(response =>
    testGroupCRUD(
      app,
      'BOOKS CRUD TEST',
      '/books',
      postRequestBody,
      'book_brave_new_world'
    )
  )
  .then(body =>
    testGroupCRUD(
      app,
      'AUTHORS CRUD TEST',
      '/authors',
      postAuthorRequestBody,
      'author_aldous_huxley'
    )
  )
  .then(body => console.log('Success', body))
  .catch(err => console.log('error', err))

TODO: testPost() example

TODO: testGet() example

TODO: testDelete() example