|
4 | 4 | const { fixtures } = require('./utils')
|
5 | 5 | const Readable = require('readable-stream').Readable
|
6 | 6 | const pull = require('pull-stream')
|
7 |
| -const path = require('path') |
8 | 7 | const expectTimeout = require('../utils/expect-timeout')
|
9 | 8 | const { getDescribe, getIt, expect } = require('../utils/mocha')
|
10 | 9 | const { supportsFileReader } = require('ipfs-utils/src/supports')
|
@@ -154,31 +153,34 @@ module.exports = (createCommon, options) => {
|
154 | 153 | })
|
155 | 154 | })
|
156 | 155 |
|
157 |
| - it('should not be able to add by path', (done) => { |
158 |
| - const validPath = path.join(process.cwd() + '/package.json') |
| 156 | + it('should add a string', (done) => { |
| 157 | + const data = 'a string' |
| 158 | + const expectedCid = 'QmQFRCwEpwQZ5aQMqCsCaFbdjNLLHoyZYDjr92v1F7HeqX' |
159 | 159 |
|
160 |
| - ipfs.add(validPath, (err, res) => { |
161 |
| - expect(err).to.exist() |
162 |
| - done() |
163 |
| - }) |
164 |
| - }) |
165 |
| - |
166 |
| - it('should not be able to add a string', (done) => { |
167 |
| - const data = `TEST${Date.now()}` |
| 160 | + ipfs.add(data, (err, filesAdded) => { |
| 161 | + expect(err).to.not.exist() |
168 | 162 |
|
169 |
| - ipfs.add(data, (err) => { |
170 |
| - expect(err).to.exist() |
171 |
| - expect(err.message).to.contain('Input not supported') |
| 163 | + expect(filesAdded).to.be.length(1) |
| 164 | + const { path, size, hash } = filesAdded[0] |
| 165 | + expect(path).to.equal(expectedCid) |
| 166 | + expect(size).to.equal(16) |
| 167 | + expect(hash).to.equal(expectedCid) |
172 | 168 | done()
|
173 | 169 | })
|
174 | 170 | })
|
175 | 171 |
|
176 |
| - it('should not be able to add a non-Buffer TypedArray', (done) => { |
177 |
| - const data = Uint8Array.from([Date.now()]) |
| 172 | + it('should add a TypedArray', (done) => { |
| 173 | + const data = Uint8Array.from([1, 3, 8]) |
| 174 | + const expectedCid = 'QmRyUEkVCuHC8eKNNJS9BDM9jqorUvnQJK1DM81hfngFqd' |
178 | 175 |
|
179 |
| - ipfs.add(data, (err) => { |
180 |
| - expect(err).to.exist() |
181 |
| - expect(err.message).to.contain('Input not supported') |
| 176 | + ipfs.add(data, (err, filesAdded) => { |
| 177 | + expect(err).to.not.exist() |
| 178 | + |
| 179 | + expect(filesAdded).to.be.length(1) |
| 180 | + const { path, size, hash } = filesAdded[0] |
| 181 | + expect(path).to.equal(expectedCid) |
| 182 | + expect(size).to.equal(11) |
| 183 | + expect(hash).to.equal(expectedCid) |
182 | 184 | done()
|
183 | 185 | })
|
184 | 186 | })
|
@@ -353,7 +355,7 @@ module.exports = (createCommon, options) => {
|
353 | 355 | })
|
354 | 356 |
|
355 | 357 | it('should fail when passed invalid input', (done) => {
|
356 |
| - const nonValid = 'sfdasfasfs' |
| 358 | + const nonValid = 138 |
357 | 359 |
|
358 | 360 | ipfs.add(nonValid, (err, result) => {
|
359 | 361 | expect(err).to.exist()
|
|
0 commit comments