# dpd-test

> easy peasy way to write deployd tests

Latest version **1.0.6** (published 2016-12-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install dpd-test
pnpm add dpd-test
yarn add dpd-test
bun add dpd-test
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2016-12-10 |
| First published | 2016-12-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Maintainers | coderofsalvation |

## Links

- npm: https://www.npmjs.com/package/dpd-test
- Repository: https://github.com/coderofsalvation/dpd-test
- Homepage: https://github.com/coderofsalvation/dpd-test#readme
- Issues: https://github.com/coderofsalvation/dpd-test/issues
- npm.io page: https://npm.io/package/dpd-test

## Dependencies (2)

- [superagent](https://npm.io/package/superagent.md) ^3.1.0
- [dpd-filebased-mongodb](https://npm.io/package/dpd-filebased-mongodb.md) ^1.2.1

## Recent versions

- 1.0.6 (latest) — 2016-12-10
- 1.0.4 — 2016-12-09
- 1.0.3 — 2016-12-07
- 1.0.2 — 2016-12-07
- 1.0.1 — 2016-12-07
- 1.0.0 — 2016-12-07

## README

Easy way to write deployd tests without mongodb 

<img src="https://media4.giphy.com/media/i9qfoiyZ4Ml0c/200_s.gif" width="150" style="width:150px"/>

![Build Status](https://travis-ci.org/--repourl=git@github.com:coderofsalvation/dpd-test..svg?branch=master)

## Usage

    $ npm install dpd-test --save
    $ NODE_PATH=node_modules node test/mytest.js

test/mytest.js:

    var dpdTest = require('dpd-test')

    dpdTest.run({
      port:3030, 
      before: function(dpd){}, 
      ready: function(dpd, done){
        console.log("ready to test")       // use your favorite testing framework here
        done()
      }, 
      done: function(err, database){
        console.log("done")                // inspect database content here  (or in file 'mongodb.test.js')
        process.exit( err ? 1 : 0 )
      }  
    })

> Voila,  there you go 

## Options 

| key       | type               | info                                                                                               |
|-----------|--------------------|----------------------------------------------------------------------------------------------------|
| ready     | fn(dpd, done)      | called when deployd server started.                                                                |
| done      | fn (err, database) | called when done() is called in ready(). You can inspect the contents of the database afterwards   |
| port      | integer (3030)     | port for the fake deployd server to listen on                                                      |
| isRoot    | boolean (false)    | this sets `req.isRoot = true` on each request when `dpd-ssh-key`-header is sent (see auth example) |
| patchFile | fn(file)           | allows patching files during bootup                                                                |
| noreset   | boolean (false)    | don't wipe database during startup (reuse db of previous test)                                     |

## Endpoint testing 

    var dpdTest = require('dpd-test')
    var request = require('superagent')
    var port = 3030

    dpdTest.run({
      port: port, 
      ready: function(dpd, done){

        request
          .post('localhost:'+port+'/user/login')
          .set('Content-Type',  'application/json')
          .set('Accept',  'application/json')
          .send({ username: "foo", password:"foo" })
          .end(function(err,  res){
            done(res.body.status != 200) // return true when error
          })

      }, 
      done: function(err, database){
        process.exit( err ? 1 : 0 )
      }  
    })

## Authenticated test

Just specify a user, and the user is automatically created and authenticated:

		dpdTest.run({
			port: port, 
			patchFile: patchFiles, 
			user: {username:"foo", "password":"foo"}, 
			ready: function(dpd, done, sessionid ){

				request
					.get('localhost:'+port+'/user/me')
					.set('Cookie', 'sid='+sessionid)
					.set('Content-Type',  'application/json')
					.set('Accept',  'application/json')
					.end(function(err,  res){
						console.dir(res.body) // logged in
						done()
					})

			}, 
			done: function(err, database){
				console.log("done") 
				process.exit( err ? 1 : 0 )
			} 
		})

> for testing roles check [dpd-acl-roles-permissions](https://npmjs.org/package/dpd-acl-roles-permissions)

## Patch files

Occasionally it can be handy to patch required files to mimic certain situations:

		var patchFiles = function(file){
			if( file.match(/resources\/foo\/config.json/) != null ){
				var mod = JSON.parse(require('fs').readFileSync(file))
				delete mod.user.properties
				return mod
			}
		}

		dpdTest.run({
			...
			patchFile: patchFiles
			...
		})

---
_Source: https://npm.io/package/dpd-test · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
