-
Notifications
You must be signed in to change notification settings - Fork 881
/
Copy pathadd-to-ipfs.spec.js
71 lines (57 loc) · 2.16 KB
/
add-to-ipfs.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
/* eslint-env mocha */
const chai = require('chai')
const path = require('path')
const { expect } = chai
const dirtyChai = require('dirty-chai')
const mockElectron = require('./mocks/electron')
const mockLogger = require('./mocks/logger')
const mockNotify = require('./mocks/notify')
const proxyquire = require('proxyquire').noCallThru()
const { makeRepository } = require('./../e2e/utils/ipfsd')
chai.use(dirtyChai)
const getFixtures = (...files) => files.map(f => path.join(__dirname, 'fixtures', f))
describe('Add To Ipfs', function () {
this.timeout(5000)
let electron, notify, addToIpfs, ipfsd, ctx
before(async () => {
const repo = await makeRepository({ start: true })
ipfsd = repo.ipfsd
ctx = {
getIpfsd: () => ipfsd,
launchWebUI: () => {}
}
})
after(() => {
if (ipfsd) ipfsd.stop()
})
beforeEach(async () => {
electron = mockElectron()
notify = mockNotify()
addToIpfs = proxyquire('../../src/add-to-ipfs', {
electron: electron,
'./common/notify': notify,
'./common/logger': mockLogger()
})
})
it('add to ipfs single file', async () => {
const cid = await addToIpfs(ctx, getFixtures('hello-world.txt'))
expect(electron.clipboard.writeText.callCount).to.equal(1)
expect(notify.notifyError.callCount).to.equal(0)
expect(notify.notify.callCount).to.equal(1)
expect(cid.toString()).to.equal('QmWGeRAEgtsHW3ec7U4qW2CyVy7eA2mFRVbk1nb24jFyks')
})
it('add to ipfs single directory', async () => {
const cid = await addToIpfs(ctx, getFixtures('dir'))
expect(electron.clipboard.writeText.callCount).to.equal(1)
expect(notify.notifyError.callCount).to.equal(0)
expect(notify.notify.callCount).to.equal(1)
expect(cid.toString()).to.equal('QmVuxXkWEyCKvQiMqVnDiwyJUUyDQZ7VsKhQDCZzPj1Yq8')
})
it('add to ipfs multiple files', async () => {
const cid = await addToIpfs(ctx, getFixtures('dir', 'hello-world.txt'))
expect(electron.clipboard.writeText.callCount).to.equal(1)
expect(notify.notifyError.callCount).to.equal(0)
expect(notify.notify.callCount).to.equal(1)
expect(cid.toString()).to.equal('QmdYASNGKMVK4HL1uzi3VCZyjQGg3M6VuLsgX5xTKL1gvH')
})
})