Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 638dc65

Browse files
committed
feature: Add Pubsub Tests
1 parent fc3f216 commit 638dc65

File tree

3 files changed

+591
-0
lines changed

3 files changed

+591
-0
lines changed

src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ exports.generic = require('./generic')
88
exports.swarm = require('./swarm')
99
exports.block = require('./block')
1010
exports.dht = require('./dht')
11+
exports.pubsub = require('./pubsub')

src/pubsub-message.js

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/* eslint-env mocha */
2+
'use strict'
3+
4+
const expect = require('chai').expect
5+
const isNode = require('detect-node')
6+
const PubsubMessage = require('../../src/pubsub-message') // eslint-disable-line no-unused-vars
7+
const PubsubMessageUtils = require('../../src/pubsub-message-utils')
8+
9+
const topicName = 'js-ipfs-api-tests'
10+
11+
// NOTE!
12+
// These tests are skipped for now until we figure out the
13+
// final data types for the messages coming over the wire
14+
15+
describe('.pubsub-message', () => {
16+
if (!isNode) {
17+
return
18+
}
19+
20+
it.skip('create message', () => {
21+
// TODO
22+
})
23+
24+
it.skip('deserialize message from JSON object', () => {
25+
const obj = {
26+
from: 'BI:ۛv�m�uyѱ����tU�+��#���V',
27+
data: 'aGk=',
28+
seqno: 'FIlj2BpyEgI=',
29+
topicIDs: [ topicName ]
30+
}
31+
try {
32+
const message = PubsubMessageUtils.deserialize(obj)
33+
expect(message.from).to.equal('AAA')
34+
expect(message.data).to.equal('hi')
35+
expect(message.seqno).to.equal('\u0014�c�\u001ar\u0012\u0002')
36+
expect(message.topicIDs.length).to.equal(1)
37+
expect(message.topicIDs[0]).to.equal(topicName)
38+
} catch (e) {
39+
expect(e).to.not.exist
40+
}
41+
})
42+
43+
describe('immutable properties', () => {
44+
const message = PubsubMessageUtils.create('A', 'hello', '123', ['hello world'])
45+
46+
it('from', () => {
47+
try {
48+
message.from = 'not allowed'
49+
} catch (e) {
50+
expect(e).to.be.an('error')
51+
expect(e.toString()).to.equal(`TypeError: Cannot set property from of #<PubsubMessage> which has only a getter`)
52+
}
53+
})
54+
55+
it('data', () => {
56+
try {
57+
message.data = 'not allowed'
58+
} catch (e) {
59+
expect(e).to.be.an('error')
60+
expect(e.toString()).to.equal(`TypeError: Cannot set property data of #<PubsubMessage> which has only a getter`)
61+
}
62+
})
63+
64+
it('seqno', () => {
65+
try {
66+
message.seqno = 'not allowed'
67+
} catch (e) {
68+
expect(e).to.be.an('error')
69+
expect(e.toString()).to.equal(`TypeError: Cannot set property seqno of #<PubsubMessage> which has only a getter`)
70+
}
71+
})
72+
73+
it('topicIDs', () => {
74+
try {
75+
message.topicIDs = ['not allowed']
76+
} catch (e) {
77+
expect(e).to.be.an('error')
78+
expect(e.toString()).to.equal(`TypeError: Cannot set property topicIDs of #<PubsubMessage> which has only a getter`)
79+
}
80+
})
81+
})
82+
})

0 commit comments

Comments
 (0)