{"id":18084715,"url":"https://github.com/coderofsalvation/dpd-test","last_synced_at":"2025-04-06T00:12:37.786Z","repository":{"id":57215808,"uuid":"75820290","full_name":"coderofsalvation/dpd-test","owner":"coderofsalvation","description":"easily mock \u0026 e2e tests for deployd endpoints, without mongodb-requirement","archived":false,"fork":false,"pushed_at":"2020-05-28T18:49:15.000Z","size":8,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T22:37:31.694Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coderofsalvation.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"custom":"https://gumroad.com/l/hGYGh"}},"created_at":"2016-12-07T09:25:49.000Z","updated_at":"2021-01-07T23:49:17.000Z","dependencies_parsed_at":"2022-08-26T13:41:57.204Z","dependency_job_id":null,"html_url":"https://github.com/coderofsalvation/dpd-test","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderofsalvation%2Fdpd-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderofsalvation%2Fdpd-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderofsalvation%2Fdpd-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderofsalvation%2Fdpd-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coderofsalvation","download_url":"https://codeload.github.com/coderofsalvation/dpd-test/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247415975,"owners_count":20935387,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-31T15:07:45.567Z","updated_at":"2025-04-06T00:12:37.764Z","avatar_url":"https://github.com/coderofsalvation.png","language":"JavaScript","funding_links":["https://gumroad.com/l/hGYGh"],"categories":[],"sub_categories":[],"readme":"Easy way to write deployd tests without mongodb \n\n\u003cimg src=\"https://media4.giphy.com/media/i9qfoiyZ4Ml0c/200_s.gif\" width=\"150\" style=\"width:150px\"/\u003e\n\n![Build Status](https://travis-ci.org/--repourl=git@github.com:coderofsalvation/dpd-test..svg?branch=master)\n\n## Usage\n\n    $ npm install dpd-test --save\n    $ NODE_PATH=node_modules node test/mytest.js\n\ntest/mytest.js:\n\n    var dpdTest = require('dpd-test')\n\n    dpdTest.run({\n      port:3030, \n      before: function(dpd){}, \n      ready: function(dpd, done){\n        console.log(\"ready to test\")       // use your favorite testing framework here\n        done()\n      }, \n      done: function(err, database){\n        console.log(\"done\")                // inspect database content here  (or in file 'mongodb.test.js')\n        process.exit( err ? 1 : 0 )\n      }  \n    })\n\n\u003e Voila,  there you go \n\n## Options \n\n| key       | type               | info                                                                                               |\n|-----------|--------------------|----------------------------------------------------------------------------------------------------|\n| ready     | fn(dpd, done)      | called when deployd server started.                                                                |\n| done      | fn (err, database) | called when done() is called in ready(). You can inspect the contents of the database afterwards   |\n| port      | integer (3030)     | port for the fake deployd server to listen on                                                      |\n| isRoot    | boolean (false)    | this sets `req.isRoot = true` on each request when `dpd-ssh-key`-header is sent (see auth example) |\n| patchFile | fn(file)           | allows patching files during bootup                                                                |\n| noreset   | boolean (false)    | don't wipe database during startup (reuse db of previous test)                                     |\n\n## Endpoint testing \n\n    var dpdTest = require('dpd-test')\n    var request = require('superagent')\n    var port = 3030\n\n    dpdTest.run({\n      port: port, \n      ready: function(dpd, done){\n\n        request\n          .post('localhost:'+port+'/user/login')\n          .set('Content-Type',  'application/json')\n          .set('Accept',  'application/json')\n          .send({ username: \"foo\", password:\"foo\" })\n          .end(function(err,  res){\n            done(res.body.status != 200) // return true when error\n          })\n\n      }, \n      done: function(err, database){\n        process.exit( err ? 1 : 0 )\n      }  \n    })\n\n## Authenticated test\n\nJust specify a user, and the user is automatically created and authenticated:\n\n\t\tdpdTest.run({\n\t\t\tport: port, \n\t\t\tpatchFile: patchFiles, \n\t\t\tuser: {username:\"foo\", \"password\":\"foo\"}, \n\t\t\tready: function(dpd, done, sessionid ){\n\n\t\t\t\trequest\n\t\t\t\t\t.get('localhost:'+port+'/user/me')\n\t\t\t\t\t.set('Cookie', 'sid='+sessionid)\n\t\t\t\t\t.set('Content-Type',  'application/json')\n\t\t\t\t\t.set('Accept',  'application/json')\n\t\t\t\t\t.end(function(err,  res){\n\t\t\t\t\t\tconsole.dir(res.body) // logged in\n\t\t\t\t\t\tdone()\n\t\t\t\t\t})\n\n\t\t\t}, \n\t\t\tdone: function(err, database){\n\t\t\t\tconsole.log(\"done\") \n\t\t\t\tprocess.exit( err ? 1 : 0 )\n\t\t\t} \n\t\t})\n\n\u003e for testing roles check [dpd-acl-roles-permissions](https://npmjs.org/package/dpd-acl-roles-permissions)\n\n## Patch files\n\nOccasionally it can be handy to patch required files to mimic certain situations:\n\n\t\tvar patchFiles = function(file){\n\t\t\tif( file.match(/resources\\/foo\\/config.json/) != null ){\n\t\t\t\tvar mod = JSON.parse(require('fs').readFileSync(file))\n\t\t\t\tdelete mod.user.properties\n\t\t\t\treturn mod\n\t\t\t}\n\t\t}\n\n\t\tdpdTest.run({\n\t\t\t...\n\t\t\tpatchFile: patchFiles\n\t\t\t...\n\t\t})\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderofsalvation%2Fdpd-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoderofsalvation%2Fdpd-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderofsalvation%2Fdpd-test/lists"}