|
1 | 1 | /* eslint-env mocha */
|
2 | 2 | /* globals apiClients */
|
3 |
| -'use strict' |
4 |
| - |
5 |
| -const expect = require('chai').expect |
6 |
| - |
7 |
| -describe('.object', () => { |
8 |
| - const testObject = Buffer(JSON.stringify({Data: 'testdata', Links: []})) |
9 |
| - const testObjectHash = 'QmPTkMuuL6PD8L2SwTwbcs1NPg14U8mRzerB1ZrrBrkSDD' |
10 |
| - const testPatchObject = Buffer(JSON.stringify({Data: 'new test data'})) |
11 |
| - const testPatchObjectHash = 'QmWJDtdQWQSajQPx1UVAGWKaSGrHVWdjnrNhbooHP7LuF2' |
12 |
| - |
13 |
| - it('object.put', (done) => { |
14 |
| - apiClients.a.object.put(testObject, 'json', (err, res) => { |
15 |
| - expect(err).to.not.exist |
16 |
| - expect(res).to.have.a.property('Hash', testObjectHash) |
17 |
| - expect(res.Links).to.be.empty |
18 |
| - done() |
19 |
| - }) |
20 |
| - }) |
21 |
| - |
22 |
| - it('object.get', (done) => { |
23 |
| - apiClients.a.object.get(testObjectHash, (err, res) => { |
24 |
| - expect(err).to.not.exist |
25 |
| - expect(res).to.have.a.property('Data', 'testdata') |
26 |
| - expect(res.Links).to.be.empty |
27 |
| - done() |
28 |
| - }) |
29 |
| - }) |
30 |
| - |
31 |
| - it('object.data', (done) => { |
32 |
| - apiClients.a.object.data(testObjectHash, (err, res) => { |
33 |
| - expect(err).to.not.exist |
34 |
| - |
35 |
| - let buf = '' |
36 |
| - res |
37 |
| - .on('error', (err) => { |
38 |
| - expect(err).to.not.exist |
39 |
| - }) |
40 |
| - .on('data', (data) => { |
41 |
| - buf += data |
42 |
| - }) |
43 |
| - .on('end', () => { |
44 |
| - expect(buf).to.equal('testdata') |
45 |
| - done() |
46 |
| - }) |
47 |
| - }) |
48 |
| - }) |
49 |
| - |
50 |
| - it('object.stat', (done) => { |
51 |
| - apiClients.a.object.stat(testObjectHash, (err, res) => { |
52 |
| - expect(err).to.not.exist |
53 |
| - expect(res).to.be.eql({ |
54 |
| - Hash: 'QmPTkMuuL6PD8L2SwTwbcs1NPg14U8mRzerB1ZrrBrkSDD', |
55 |
| - NumLinks: 0, |
56 |
| - BlockSize: 10, |
57 |
| - LinksSize: 2, |
58 |
| - DataSize: 8, |
59 |
| - CumulativeSize: 10 |
60 |
| - }) |
61 |
| - done() |
62 |
| - }) |
63 |
| - }) |
64 |
| - |
65 |
| - it('object.links', (done) => { |
66 |
| - apiClients.a.object.links(testObjectHash, (err, res) => { |
67 |
| - expect(err).to.not.exist |
68 | 3 |
|
69 |
| - expect(res).to.be.eql({ |
70 |
| - Hash: 'QmPTkMuuL6PD8L2SwTwbcs1NPg14U8mRzerB1ZrrBrkSDD' |
71 |
| - }) |
72 |
| - done() |
73 |
| - }) |
74 |
| - }) |
75 |
| - |
76 |
| - describe('object.patch', () => { |
77 |
| - before((done) => { |
78 |
| - apiClients.a.object.put(testPatchObject, 'json', (err, res) => { |
79 |
| - expect(err).to.not.exist |
80 |
| - done() |
81 |
| - }) |
82 |
| - }) |
83 |
| - |
84 |
| - it('.addLink', (done) => { |
85 |
| - apiClients.a.object.patch |
86 |
| - .addLink(testObjectHash, 'next', testPatchObjectHash, (err, res) => { |
87 |
| - expect(err).to.not.exist |
88 |
| - expect(res).to.be.eql({ |
89 |
| - Hash: 'QmZFdJ3CQsY4kkyQtjoUo8oAzsEs5BNguxBhp8sjQMpgkd' |
90 |
| - }) |
91 |
| - apiClients.a.object.get(res.Hash, (err, res) => { |
92 |
| - expect(err).to.not.exist |
93 |
| - expect(res).to.be.eql({ |
94 |
| - Data: 'testdata', |
95 |
| - Links: [{ |
96 |
| - Name: 'next', |
97 |
| - Hash: 'QmWJDtdQWQSajQPx1UVAGWKaSGrHVWdjnrNhbooHP7LuF2', |
98 |
| - Size: 15 |
99 |
| - }] |
100 |
| - }) |
101 |
| - done() |
102 |
| - }) |
103 |
| - }) |
104 |
| - }) |
105 |
| - |
106 |
| - it('.rmLink', (done) => { |
107 |
| - apiClients.a.object.patch |
108 |
| - .rmLink('QmZFdJ3CQsY4kkyQtjoUo8oAzsEs5BNguxBhp8sjQMpgkd', 'next', (err, res) => { |
109 |
| - expect(err).to.not.exist |
110 |
| - expect(res).to.be.eql({ |
111 |
| - Hash: testObjectHash |
112 |
| - }) |
113 |
| - apiClients.a.object.get(res.Hash, (err, res) => { |
114 |
| - expect(err).to.not.exist |
115 |
| - expect(res).to.be.eql({ |
116 |
| - Data: 'testdata', |
117 |
| - Links: [] |
118 |
| - }) |
119 |
| - done() |
120 |
| - }) |
121 |
| - }) |
122 |
| - }) |
123 |
| - |
124 |
| - it('.appendData', (done) => { |
125 |
| - apiClients.a.object.patch |
126 |
| - .appendData(testObjectHash, new Buffer(' hello'), (err, res) => { |
127 |
| - expect(err).to.not.exist |
128 |
| - expect(res).to.be.eql({ |
129 |
| - Hash: 'Qmcjhr2QztQxCAoEf8tJPTGTVkTsUrTQ36JurH14DNYNsc' |
130 |
| - }) |
131 |
| - apiClients.a.object.get(res.Hash, (err, res) => { |
132 |
| - expect(err).to.not.exist |
133 |
| - expect(res).to.be.eql({ |
134 |
| - Data: 'testdata hello', |
135 |
| - Links: [] |
136 |
| - }) |
137 |
| - done() |
138 |
| - }) |
139 |
| - }) |
140 |
| - }) |
141 |
| - it('.setData', (done) => { |
142 |
| - apiClients.a.object.patch |
143 |
| - .setData(testObjectHash, new Buffer('hello world'), (err, res) => { |
144 |
| - expect(err).to.not.exist |
145 |
| - expect(res).to.be.eql({ |
146 |
| - Hash: 'QmU1Sq1B7RPQD2XcQNLB58qJUyJffVJqihcxmmN1STPMxf' |
147 |
| - }) |
148 |
| - apiClients.a.object.get(res.Hash, (err, res) => { |
149 |
| - expect(err).to.not.exist |
150 |
| - expect(res).to.be.eql({ |
151 |
| - Data: 'hello world', |
152 |
| - Links: [] |
153 |
| - }) |
154 |
| - done() |
155 |
| - }) |
156 |
| - }) |
157 |
| - }) |
158 |
| - }) |
159 |
| - |
160 |
| - it('object.new', (done) => { |
161 |
| - apiClients.a.object.new('unixfs-dir', (err, res) => { |
162 |
| - expect(err).to.not.exist |
163 |
| - expect(res).to.deep.equal({ |
164 |
| - Hash: 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn' |
165 |
| - }) |
166 |
| - done() |
167 |
| - }) |
168 |
| - }) |
169 |
| - |
170 |
| - describe('promise', () => { |
171 |
| - it('object.put', () => { |
172 |
| - return apiClients.a.object.put(testObject, 'json') |
173 |
| - .then((res) => { |
174 |
| - expect(res).to.have.a.property('Hash', testObjectHash) |
175 |
| - expect(res.Links).to.be.empty |
176 |
| - }) |
177 |
| - }) |
178 |
| - |
179 |
| - it('object.get', () => { |
180 |
| - return apiClients.a.object.get(testObjectHash) |
181 |
| - .then((res) => { |
182 |
| - expect(res).to.have.a.property('Data', 'testdata') |
183 |
| - expect(res.Links).to.be.empty |
184 |
| - }) |
185 |
| - }) |
186 |
| - |
187 |
| - it('object.data', (done) => { |
188 |
| - return apiClients.a.object.data(testObjectHash) |
189 |
| - .then((res) => { |
190 |
| - let buf = '' |
191 |
| - res |
192 |
| - .on('error', (err) => { |
193 |
| - throw err |
194 |
| - }) |
195 |
| - .on('data', (data) => { |
196 |
| - buf += data |
197 |
| - }) |
198 |
| - .on('end', () => { |
199 |
| - expect(buf).to.equal('testdata') |
200 |
| - done() |
201 |
| - }) |
202 |
| - }) |
203 |
| - }) |
| 4 | +'use strict' |
204 | 5 |
|
205 |
| - it('object.stat', () => { |
206 |
| - return apiClients.a.object.stat(testObjectHash) |
207 |
| - .then((res) => { |
208 |
| - expect(res).to.be.eql({ |
209 |
| - Hash: 'QmPTkMuuL6PD8L2SwTwbcs1NPg14U8mRzerB1ZrrBrkSDD', |
210 |
| - NumLinks: 0, |
211 |
| - BlockSize: 10, |
212 |
| - LinksSize: 2, |
213 |
| - DataSize: 8, |
214 |
| - CumulativeSize: 10 |
215 |
| - }) |
216 |
| - }) |
217 |
| - }) |
| 6 | +const test = require('interface-ipfs-core') |
218 | 7 |
|
219 |
| - it('object.links', () => { |
220 |
| - return apiClients.a.object.links(testObjectHash) |
221 |
| - .then((res) => { |
222 |
| - expect(res).to.be.eql({ |
223 |
| - Hash: 'QmPTkMuuL6PD8L2SwTwbcs1NPg14U8mRzerB1ZrrBrkSDD' |
224 |
| - }) |
225 |
| - }) |
226 |
| - }) |
| 8 | +const common = { |
| 9 | + setup: function (cb) { |
| 10 | + cb(null, apiClients.a) |
| 11 | + }, |
| 12 | + teardown: function (cb) { |
| 13 | + cb() |
| 14 | + } |
| 15 | +} |
227 | 16 |
|
228 |
| - it('object.new', () => { |
229 |
| - return apiClients.a.object.new('unixfs-dir') |
230 |
| - .then((res) => { |
231 |
| - expect(res).to.deep.equal({ |
232 |
| - Hash: 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn' |
233 |
| - }) |
234 |
| - }) |
235 |
| - }) |
236 |
| - }) |
237 |
| -}) |
| 17 | +test.object(common) |
0 commit comments