Skip to content

Commit 728b358

Browse files
committed
Make add.js in lib and create a test
1 parent 643044f commit 728b358

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

lib/add.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = addRow
22

33
function addRow (jawn, key, value) {
4-
jawn.kv.put(key, JSON.stringify(value), function (err, node) {
4+
jawn.kv.put(key, value, function (err, node) {
55
if (err) console.error(err)
66
else console.log(node.key + ': ' + node.value)
77
})

lib/importkv.js

Whitespace-only changes.

test/add.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,29 @@ var memdb = require('memdb')
44

55
test('add 3 rows', function (t) {
66
var jawn = freshJawn()
7+
78
var testValues = [
89
'{"foo":"bar","name":"josie","age":"35"}',
910
'{"foo":"baz","name":"eloise","age":"71"}',
1011
'{"foo":"baz","name":"francoise","age":"5"}'
1112
]
12-
/*
13+
1314
var expected = [
1415
'0: {"foo":"bar","name":"josie","age":"35"}',
1516
'1: {"foo":"baz","name":"eloise","age":"71"}',
1617
'2: {"foo":"baz","name":"francoise","age":"5"}'
1718
]
18-
*/
1919

20-
for (var i = 0; testValues.length; i++) {
20+
for (var i = 0; i < testValues.length; i++) {
2121
jawn.addRow(i, testValues[i])
2222
}
2323

2424
jawn.kv.on('put', function (key, value, node) {
25-
console.log(key + ': ' + value)
25+
t.equal(key + ': ' + value, expected.shift(), key + ' is the right value')
26+
27+
if (expected.length === 0) {
28+
t.end()
29+
}
2630
})
2731
})
2832

0 commit comments

Comments
 (0)