Skip to content

thanpolas/crude-test

Repository files navigation

crude-test

API Test Helpers for crude.

Build Status

Install

Install the module using NPM:

npm install crude-test --save
  1. Overview
  2. API

Overview

crude-test provides a convenient, fast and effective way to test your endpoints that were created using the crude package. Usage is pretty straighforward:

var CrudeTest = require('crude-test');

// load internal modules
var userFix = require('./fixtures/user.fix');
var UserEnt = require('./entities/user.ent');

// initialize the Crude tester
var crudeTest = new CrudeTest({
    endpoint: '/user',
    fixture: userFix.one,
    stringAttr: 'firstName',
    idAttr: '_id',
    uniqueAttr: 'email',
    Entity: UserEnt,
});

// run the tests
crudeTest.run();

API

Constructor

  • Object= optOptions Optionally define a set of options.

The crude-test package exposes a constructor that you need to invoke with the new keyword.

var CrudeTest = require('crude-test');

var crudeTest = new CrudeTest();

setup(options)

  • Object options A set of options

You may invoke setup() after the instanciation to configure the crude-test instance.

Options

Find bellow all the available options to configure crude-test. In type definitions the = symbol means that the property is optional, all properties not having the equal symbol are REQUIRED:

* *hostname* `string` The hostname to perform the tests against, i.e. `http://localhost:3000`.
* *endpoint* `string` The endpoint to test, i.e. `/user`.
* *fixture* `Object` the data fixture to use, provide a data object to use for creating items.
* *stringAttr* `string` A string attribute in the fixture to use for updating and query filtering, any string type attribute will do.
* *uniqueAttr* `string` An attribute that acts as a unique identifier of the record, e.g. the email if the model is a user, in an empty db this can be any field, not neccessarily an actually unique one.
* *Entity* `Entity` The [entity instance](https://github.com/thanpolas/entity) of the model to be tested.
* *create* `Object` Create OP related parameters:
    * *response* `Function` A node.js style callback with the tests res.
* *readList* `Object` Read List OP related parameters:
    * *response* `Function` A node.js style callback with the tests res.
* *readItem* `Object` Read Item OP related parameters:
    * *response* `Function` A node.js style callback with the tests res.
* *readFilter* `Object` Read Filter OP related parameters:
    * *response* `Function` A node.js style callback with the tests res.
* *update* `Object` Update OP related parameters:
    * *response* `Function` A node.js style callback with the tests res.
* *delete* `Object` Delete OP related parameters:
    * *response* `Function` A node.js style callback with the tests res.

[⬆]

Release History

  • v0.0.1, 04 Jul 2014
    • Big Bang

License

Copyright (c) 2014 Thanasis Polychronakis. Licensed under the MIT license.

About

API Test Helpers for crude.

Resources

License

Stars

Watchers

Forks

Packages

No packages published