This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathpublish.js
60 lines (48 loc) · 1.6 KB
/
publish.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
/* eslint-env mocha */
'use strict'
const { Buffer } = require('buffer')
const { nanoid } = require('nanoid')
const { getTopic } = require('./utils')
const { getDescribe, getIt, expect } = require('../utils/mocha')
const testTimeout = require('../utils/test-timeout')
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
* @param {Object} options
*/
module.exports = (common, options) => {
const describe = getDescribe(options)
const it = getIt(options)
describe('.pubsub.publish', function () {
this.timeout(80 * 1000)
let ipfs
before(async () => {
ipfs = (await common.spawn()).api
})
after(() => common.clean())
it('should respect timeout option when publishing a pubsub message', () => {
return testTimeout(() => ipfs.pubsub.publish(getTopic(), 'derp', {
timeout: 1
}))
})
it('should publish message from string', () => {
const topic = getTopic()
return ipfs.pubsub.publish(topic, 'hello friend')
})
it('should fail with undefined msg', async () => {
const topic = getTopic()
await expect(ipfs.pubsub.publish(topic)).to.eventually.rejectedWith('argument "data" is required')
})
it('should publish message from buffer', () => {
const topic = getTopic()
return ipfs.pubsub.publish(topic, Buffer.from(nanoid()))
})
it('should publish 10 times within time limit', async () => {
const count = 10
const topic = getTopic()
for (let i = 0; i < count; i++) {
await ipfs.pubsub.publish(topic, Buffer.from(nanoid()))
}
})
})
}