-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BASIC CRUD complete - delete record works - #9
- Loading branch information
Showing
7 changed files
with
69 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
var http = require('http'); | ||
var config = require('../config'); | ||
|
||
function del(record, callback) { | ||
|
||
var options = { | ||
host: config.host, | ||
port: config.port, | ||
path: '/' + record.index + '/' + record.type + '/' + record.id, | ||
method: 'DELETE' | ||
}; | ||
|
||
var resStr = ''; | ||
// Set up the request | ||
var req = http.request(options, function(res) { | ||
res.setEncoding('utf8'); | ||
var resStr = ''; | ||
res.on('data', function (chunk) { | ||
resStr += chunk; | ||
}).on('end', function () { | ||
callback(null, JSON.parse(resStr)); | ||
}); | ||
}).end(); | ||
|
||
} | ||
|
||
module.exports = { | ||
del : del | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var test = require('tape'); | ||
var chalk = require('chalk'); | ||
var faker = require('faker'); | ||
|
||
var C = require('../lib/create.js'); | ||
var R = require('../lib/read.js'); | ||
var D = require('../lib/delete.js'); | ||
|
||
test(chalk.yellow('DELETE a Record'), function (t) { | ||
var record = { | ||
type: 'tweet', | ||
index: 'twitter', | ||
id: Math.floor(Math.random() * (1000000)), | ||
message: faker.hacker.phrase() | ||
} | ||
|
||
var rec = {}; // make a copy of rec for later. | ||
for(var key in record) { | ||
if(record.hasOwnProperty(key)) { | ||
rec[key] = record[key]; | ||
} | ||
} | ||
C.create(record, function(err, res) { | ||
D.del(rec, function(err3, res3) { | ||
t.equal(res3.found, true, chalk.green("✓ Record Existed - So Delete it!")); | ||
t.equal(err3, null, chalk.green("✓ No Errors Deleting")); | ||
// attempt to read record - it should fail | ||
R.read(rec, function(err4, res4){ | ||
t.equal(res4.found, false, chalk.green("✓ Record Deleted")); | ||
t.end(); | ||
}) | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters