|
1 | 1 | /* eslint-env mocha */
|
2 |
| -/* globals apiClients */ |
| 2 | +/* eslint max-nested-callbacks: ["error", 8] */ |
| 3 | + |
3 | 4 | 'use strict'
|
4 | 5 |
|
5 | 6 | const expect = require('chai').expect
|
6 | 7 |
|
7 | 8 | module.exports = (common) => {
|
8 |
| - describe.only('.block', () => { |
9 |
| - const blorbKey = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ' |
10 |
| - const blorb = Buffer('blorb') |
11 |
| - |
12 |
| - it('returns an error when putting an array of files', () => { |
13 |
| - return apiClients.a.block.put([blorb, blorb], (err) => { |
14 |
| - console.log(err) |
15 |
| - expect(err).to.be.an.instanceof(Error) |
16 |
| - }) |
17 |
| - }) |
| 9 | + describe('.block', () => { |
| 10 | + let ipfs |
18 | 11 |
|
19 |
| - it('block.put', (done) => { |
20 |
| - apiClients.a.block.put(blorb, (err, res) => { |
21 |
| - expect(err).to.not.exist |
22 |
| - expect(res).to.have.a.property('Key', 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ') |
23 |
| - done() |
24 |
| - }) |
25 |
| - }) |
| 12 | + before(function (done) { |
| 13 | + // CI takes longer to instantiate the daemon, |
| 14 | + // so we need to increase the timeout for the |
| 15 | + // before step |
| 16 | + this.timeout(20 * 1000) |
26 | 17 |
|
27 |
| - it('block.get', (done) => { |
28 |
| - apiClients.a.block.get(blorbKey, (err, res) => { |
| 18 | + common.setup((err, factory) => { |
29 | 19 | expect(err).to.not.exist
|
30 |
| - |
31 |
| - let buf = '' |
32 |
| - res |
33 |
| - .on('data', function (data) { buf += data }) |
34 |
| - .on('end', function () { |
35 |
| - expect(buf).to.be.equal('blorb') |
36 |
| - done() |
37 |
| - }) |
| 20 | + factory.spawnNode((err, node) => { |
| 21 | + expect(err).to.not.exist |
| 22 | + ipfs = node |
| 23 | + done() |
| 24 | + }) |
38 | 25 | })
|
39 | 26 | })
|
40 | 27 |
|
41 |
| - it('block.stat', (done) => { |
42 |
| - apiClients.a.block.stat(blorbKey, (err, res) => { |
43 |
| - expect(err).to.not.exist |
44 |
| - expect(res).to.have.property('Key') |
45 |
| - expect(res).to.have.property('Size') |
46 |
| - done() |
47 |
| - }) |
| 28 | + after((done) => { |
| 29 | + common.teardown(done) |
48 | 30 | })
|
49 | 31 |
|
50 |
| - describe('promise', () => { |
51 |
| - it('returns an error when putting an array of files', () => { |
52 |
| - return apiClients.a.block.put([blorb, blorb]) |
53 |
| - .catch((err) => { |
54 |
| - expect(err).to.be.an.instanceof(Error) |
55 |
| - }) |
| 32 | + describe('callback API', () => { |
| 33 | + it('.put', (done) => { |
| 34 | + const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ' |
| 35 | + const blob = Buffer('blorb') |
| 36 | + |
| 37 | + ipfs.block.put(blob, (err, res) => { |
| 38 | + expect(err).to.not.exist |
| 39 | + expect(res).to.have.a.property('Key', expectedHash) |
| 40 | + done() |
| 41 | + }) |
56 | 42 | })
|
57 | 43 |
|
58 |
| - it('block.put', () => { |
59 |
| - return apiClients.a.block.put(blorb) |
60 |
| - .then((res) => { |
61 |
| - expect(res).to.have.a.property('Key', 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ') |
62 |
| - }) |
| 44 | + it('.put error with array of blocks', () => { |
| 45 | + const blob = Buffer('blorb') |
| 46 | + |
| 47 | + ipfs.block.put([blob, blob], (err) => { |
| 48 | + expect(err).to.be.an.instanceof(Error) |
| 49 | + }) |
63 | 50 | })
|
64 | 51 |
|
65 | 52 | it('block.get', (done) => {
|
66 |
| - return apiClients.a.block.get(blorbKey) |
67 |
| - .then((res) => { |
68 |
| - let buf = '' |
69 |
| - res |
70 |
| - .on('data', function (data) { buf += data }) |
71 |
| - .on('end', function () { |
72 |
| - expect(buf).to.be.equal('blorb') |
73 |
| - done() |
74 |
| - }) |
75 |
| - }) |
| 53 | + const hash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ' |
| 54 | + |
| 55 | + ipfs.block.get(hash, (err, res) => { |
| 56 | + expect(err).to.not.exist |
| 57 | + |
| 58 | + // TODO review this |
| 59 | + let buf = '' |
| 60 | + res |
| 61 | + .on('data', function (data) { buf += data }) |
| 62 | + .on('end', function () { |
| 63 | + expect(buf).to.be.equal('blorb') |
| 64 | + done() |
| 65 | + }) |
| 66 | + }) |
76 | 67 | })
|
77 | 68 |
|
78 |
| - it('block.stat', () => { |
79 |
| - return apiClients.a.block.stat(blorbKey) |
80 |
| - .then((res) => { |
81 |
| - expect(res).to.have.property('Key') |
82 |
| - expect(res).to.have.property('Size') |
83 |
| - }) |
| 69 | + it('block.stat', (done) => { |
| 70 | + const hash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ' |
| 71 | + |
| 72 | + ipfs.block.stat(hash, (err, res) => { |
| 73 | + expect(err).to.not.exist |
| 74 | + expect(res).to.have.property('Key') |
| 75 | + expect(res).to.have.property('Size') |
| 76 | + done() |
| 77 | + }) |
84 | 78 | })
|
85 | 79 | })
|
| 80 | + |
| 81 | + describe('promise API', () => { |
| 82 | + }) |
86 | 83 | })
|
87 | 84 | }
|
0 commit comments