/
get.js
37 lines (34 loc) · 1.3 KB
/
get.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
var helpers = require('../helpers');
var harness = helpers.harness();
var it = harness.it;
it('should be able to fetch an attachment', function(assert) {
var locals = this;
locals.db.attachment.insert('new_string', 'att', 'Hello', 'text/plain',
function(error, hello) {
assert.equal(error, null, 'should store `hello`');
assert.equal(hello.ok, true, 'response ok');
assert.ok(hello.rev, 'should have a revision number');
locals.db.attachment.get('new_string', 'att',
function(error, helloWorld) {
assert.equal(error, null, 'should get `hello`');
assert.equal('Hello', helloWorld.toString(), 'string is reflexive');
assert.end();
});
});
});
it('should insert and fetch a binary file', function(assert) {
var locals = this;
locals.db.attachment.insert('new_binary', 'att',
new Buffer('123'), 'text/plain', function(error, hello) {
assert.equal(error, null, 'should store `123`');
assert.equal(hello.ok, true, 'response ok');
assert.ok(hello.rev, 'should have a revision number');
locals.db.attachment.get('new_binary', 'att',
function(error, binaryData) {
assert.equal(error, null, 'should get the binary data');
assert.equal('123', binaryData.toString(), 'binary data is reflexive');
assert.end();
});
});
});