|
4 | 4 | const expect = require('../helpers/chai')
|
5 | 5 | const cli = require('../helpers/cli')
|
6 | 6 | const sinon = require('sinon')
|
| 7 | +const CID = require('cids') |
| 8 | +const cid = new CID('QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn') |
7 | 9 |
|
8 | 10 | describe('flush', () => {
|
9 | 11 | const path = '/foo'
|
10 | 12 | let ipfs
|
| 13 | + let print |
| 14 | + let output |
11 | 15 |
|
12 | 16 | beforeEach(() => {
|
13 | 17 | ipfs = {
|
14 | 18 | files: {
|
15 |
| - flush: sinon.stub() |
| 19 | + flush: sinon.stub().resolves(cid) |
16 | 20 | }
|
17 | 21 | }
|
| 22 | + print = (msg = '', newline = true) => { |
| 23 | + output += newline ? msg + '\n' : msg |
| 24 | + } |
18 | 25 | })
|
19 | 26 |
|
20 | 27 | it('should flush a path', async () => {
|
21 |
| - await cli(`files flush ${path}`, { ipfs }) |
| 28 | + await cli(`files flush ${path}`, { ipfs, print }) |
22 | 29 |
|
23 | 30 | expect(ipfs.files.flush.callCount).to.equal(1)
|
24 | 31 | expect(ipfs.files.flush.getCall(0).args).to.deep.equal([
|
25 | 32 | path,
|
26 | 33 | {}
|
27 | 34 | ])
|
| 35 | + expect(output).to.include(cid.toString()) |
28 | 36 | })
|
29 | 37 |
|
30 | 38 | it('should flush without a path', async () => {
|
31 |
| - await cli('files flush', { ipfs }) |
| 39 | + await cli('files flush', { ipfs, print }) |
| 40 | + |
| 41 | + expect(ipfs.files.flush.callCount).to.equal(1) |
| 42 | + expect(ipfs.files.flush.getCall(0).args).to.deep.equal([ |
| 43 | + '/', |
| 44 | + {} |
| 45 | + ]) |
| 46 | + expect(output).to.include(cid.toString()) |
| 47 | + }) |
| 48 | + |
| 49 | + it('should flush with a different CID base', async () => { |
| 50 | + await cli('files flush --cid-base base64', { ipfs, print }) |
32 | 51 |
|
33 | 52 | expect(ipfs.files.flush.callCount).to.equal(1)
|
34 | 53 | expect(ipfs.files.flush.getCall(0).args).to.deep.equal([
|
35 | 54 | '/',
|
36 | 55 | {}
|
37 | 56 | ])
|
| 57 | + expect(output).to.include(cid.toV1().toString('base64')) |
38 | 58 | })
|
39 | 59 | })
|
0 commit comments