This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 297
/
Copy pathblock.spec.js
86 lines (75 loc) · 2.2 KB
/
block.spec.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 8] */
/* globals apiClients */
'use strict'
const expect = require('chai').expect
describe('.block', () => {
const blorbKey = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
const blorb = Buffer('blorb')
it('returns an error when putting an array of files', () => {
return apiClients.a.block.put([blorb, blorb], (err) => {
expect(err).to.be.an.instanceof(Error)
})
})
it('block.put', (done) => {
apiClients.a.block.put(blorb, (err, res) => {
expect(err).to.not.exist
expect(res).to.have.a.property('Key', 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ')
done()
})
})
it('block.get', (done) => {
apiClients.a.block.get(blorbKey, (err, res) => {
expect(err).to.not.exist
let buf = ''
res
.on('data', function (data) { buf += data })
.on('end', function () {
expect(buf).to.be.equal('blorb')
done()
})
})
})
it('block.stat', (done) => {
apiClients.a.block.stat(blorbKey, (err, res) => {
expect(err).to.not.exist
expect(res).to.have.property('Key')
expect(res).to.have.property('Size')
done()
})
})
describe('promise', () => {
it('returns an error when putting an array of files', () => {
return apiClients.a.block.put([blorb, blorb])
.catch((err) => {
expect(err).to.be.an.instanceof(Error)
})
})
it('block.put', () => {
return apiClients.a.block.put(blorb)
.then((res) => {
expect(res).to.have.a.property('Key', 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ')
})
})
it('block.get', (done) => {
apiClients.a.block.get(blorbKey)
.then((res) => {
let buf = ''
res
.on('data', function (data) { buf += data })
.on('end', function () {
expect(buf).to.be.equal('blorb')
done()
})
})
.catch(done)
})
it('block.stat', () => {
return apiClients.a.block.stat(blorbKey)
.then((res) => {
expect(res).to.have.property('Key')
expect(res).to.have.property('Size')
})
})
})
})