Skip to content

Commit

Permalink
Added support for put and delete routes
Browse files Browse the repository at this point in the history
  • Loading branch information
GavinDmello committed Dec 28, 2017
1 parent 0e1ab10 commit 16cc8a2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
25 changes: 16 additions & 9 deletions lib/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ network.prototype.postRequest = function(hostInfo, request, done) {
port: hostInfo.port,
headers : request.headers,
path: request.url || '/',
method: 'POST',
method: request.method,
pool: this.pool
}, callback)
req.on('error', function requestError(err) {
Expand Down Expand Up @@ -139,14 +139,21 @@ network.prototype.postRequest = function(hostInfo, request, done) {
}

network.prototype.sendRequest = function(hostInfo, request, cb) {
if (request.method === 'GET') {
this.getRequest(hostInfo, request, function handleGet(response) {
cb(response)
})
} else {
this.postRequest(hostInfo, request, function handlePost(response) {
cb(response)
})
switch(request.method) {
case 'GET' :
this.getRequest(hostInfo, request, function handleGet(response) {
cb(response)
})
break

case 'POST' :
case 'PUT' :
case 'DELETE':
this.postRequest(hostInfo, request, function handlePost(response) {
cb(response)
})
break

}
}

Expand Down
18 changes: 17 additions & 1 deletion tests/simple-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ process.env.NODE_ENV = 'test'
var request = require('supertest')
var testConfig = require('./test-config.json')

describe('simple tests', () => {
describe('method tests', () => {
var server
var originalCache = require('../config.json')
beforeEach((done) => {
Expand Down Expand Up @@ -40,6 +40,22 @@ describe('simple tests', () => {
.send("hi")
.expect(200, done)

})

it('basic put request', (done) => {
request(server)
.put('/status/200')
.send("hi")
.expect(200, done)

})

it('basic delete request', (done) => {
request(server)
.delete('/status/200')
.send("hi")
.expect(200, done)

})

})

0 comments on commit 16cc8a2

Please sign in to comment.