0.8.3 • Published 4 years ago

flare-gun v0.8.3

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Flare Gun Build Status

A JSON REST API testing framework

Install

$ npm install flare-gun

Example, using mocha

$ npm install mocha Joi

Default config for Joi validation:

{
  convert: false,
  presence: 'required'
}
var Joi = require('joi')
var flareGun = require('flare-gun')
var flare = flareGun.route('http://myapp.com/api')

describe('MyApp', function () {
  it('gets users', function () {
    return flare
      .get('/users')
      .expect(200, Joi.array().includes({
        id: Joi.number(),
        username: Joi.string().required(),
        avatar: Joi.string()
      }))
  })

  it('creates users', function () {
    return flare
      .post('/users', {username: 'joe'})
      .expect(200)
      .stash('joe')
      .get('/users/:joe.id')
      .expect(200, {
        id: Joi.number(),
        username: Joi.string().required(),
        avatar: Joi.string()
      })
  })
})

Usage

.request({String uri, String method}) -> FlarePromise
.get(String uri, Object queryString, Object options) -> FlarePromise
.expect(String statusCode, Object|{Joi} response) -> FlarePromise
.post(String uri, Object body, Object options) -> FlarePromise
.put(String uri, Object body, Object options) -> FlarePromise
.patch(String uri, Object body, Object options) -> FlarePromise
.del(String uri, Object body, Object options) -> FlarePromise
.stash(String name, Function<Stash> -> Object) -> FlarePromise
.thru(Function<FlarePromise>(FlarePromise)) -> FlarePromise
.do(Function<FlarePromise>) -> FlarePromise

Options are passed through to request Stashed variables can be injected in any string, by prefixing with a :
e.g.

flareGun
  .post('/user')
  .stash('joe')
  .post('/users/:joe.id', {name: ':joe.name'})
  .expect(200, {id: ':joe.id'})
  .post('/users/:joe.id', {name: ':joe.name'})
  .expect(200, Joi.object().keys({
    id: ':joi.id'
  }))
  .post('/users/friends', ':joe')
  .expect(200, ':joe.id')
  .get('/users/:joe.id')
  .expect(200, ':joe')
.actor(String name, Object requestObj) -> FlarePromise

requestObj gets combind with requests before being passed to request.js

.as(String name) -> FlarePromise
flareGun
  .actor('joe', {
    auth: {
      user: 'joe',
      pass: 'joePass'
    }
  })
  .actor('anon', {})
  .as('joe')
  .get('/asJoe')
  .as('anon')
  .get('/asAnon')
.route(String url) -> FlarePromise

Set the base url for requests

.express({Express} app) -> FlarePromise

Pass in an express server object to make calls to, instead of a url Also accepts a promise of an express server

.close() -> FlarePromise

Close express server. May close more connections in the future.

.exoid(String path, Object body) -> FlarePromise

Calls an exoid method at '/exoid'. See https://github.com/Zorium/exoid

Contributing

$ npm test

Changelog

  • 0.7.x -> 0.8.x
    • expect(cb) is now passed res.body instead of res
  • 0.6.x -> 0.7.x
    • add graph()
    • upgrade Joi (now peer dependency)
    • add userAgent string default
    • expect(cb) promise support
  • 0.5.x -> 0.6.0
    • Flare gun has become properly pure, which means that side effects will not impact other chains
      This also means that Flare gun has become a singleton, without needing to be instantiated.
    • Removed flare method
    • Added thru method
0.8.3

4 years ago

0.8.2

4 years ago

0.8.1

6 years ago

0.8.0

6 years ago

0.7.2

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.6.8

7 years ago

0.6.7

8 years ago

0.6.6

9 years ago

0.6.5

9 years ago

0.6.4

9 years ago

0.6.3

9 years ago

0.6.2

9 years ago

0.6.1

9 years ago

0.6.0

9 years ago

0.5.8

9 years ago

0.5.7

9 years ago

0.5.6

9 years ago

0.5.5

9 years ago

0.5.4

9 years ago

0.5.3

9 years ago

0.5.2

9 years ago

0.5.1

10 years ago

0.5.0

10 years ago

0.4.1

10 years ago

0.4.0

10 years ago

0.3.4

10 years ago

0.3.3

10 years ago

0.3.2

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.4

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago