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

Commit 0a221fc

Browse files
committed
Fix pubsub-message tests.
1 parent 638dc65 commit 0a221fc

File tree

2 files changed

+78
-59
lines changed

2 files changed

+78
-59
lines changed

src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ exports.swarm = require('./swarm')
99
exports.block = require('./block')
1010
exports.dht = require('./dht')
1111
exports.pubsub = require('./pubsub')
12+
exports.pubsubMessage = require('./pubsub-message')

src/pubsub-message.js

+77-59
Original file line numberDiff line numberDiff line change
@@ -3,80 +3,98 @@
33

44
const expect = require('chai').expect
55
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'
106

117
// NOTE!
12-
// These tests are skipped for now until we figure out the
8+
// (Most of) these tests are skipped for now until we figure out the
139
// final data types for the messages coming over the wire
1410

15-
describe('.pubsub-message', () => {
16-
if (!isNode) {
17-
return
18-
}
11+
const topicName = 'js-ipfs-api-tests'
1912

20-
it.skip('create message', () => {
21-
// TODO
22-
})
13+
module.exports = (common, deps) => {
14+
// Make sure the needed dependencies are injected
15+
expect(deps.PubsubMessage).to.exist
16+
expect(deps.PubsubMessageUtils).to.exist
2317

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-
})
18+
const PubsubMessage = deps.PubsubMessage // eslint-disable-line no-unused-vars
19+
const PubsubMessageUtils = deps.PubsubMessageUtils // eslint-disable-line no-unused-vars
4220

43-
describe('immutable properties', () => {
44-
const message = PubsubMessageUtils.create('A', 'hello', '123', ['hello world'])
21+
// TESTS
22+
describe('.pubsub-message', () => {
23+
if (!isNode) {
24+
return
25+
}
4526

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-
}
27+
it.skip('create message', () => {
28+
// TODO
5329
})
5430

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`)
31+
it.skip('deserialize message from JSON object', () => {
32+
const obj = {
33+
from: 'BI:ۛv�m�uyѱ����tU�+��#���V',
34+
data: 'aGk=',
35+
seqno: 'FIlj2BpyEgI=',
36+
topicIDs: [ topicName ]
6137
}
62-
})
63-
64-
it('seqno', () => {
6538
try {
66-
message.seqno = 'not allowed'
39+
const message = PubsubMessageUtils.deserialize(obj)
40+
expect(message.from).to.equal('AAA')
41+
expect(message.data).to.equal('hi')
42+
expect(message.seqno).to.equal('\u0014�c�\u001ar\u0012\u0002')
43+
expect(message.topicIDs.length).to.equal(1)
44+
expect(message.topicIDs[0]).to.equal(topicName)
6745
} 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`)
46+
expect(e).to.not.exist
7047
}
7148
})
7249

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-
}
50+
describe('immutable properties', () => {
51+
const sender = 'A'
52+
const data = 'hello'
53+
const seqno = '123'
54+
const topicIDs = ['hello world']
55+
56+
const message = PubsubMessageUtils.create(sender, data, seqno, topicIDs)
57+
58+
it('from', () => {
59+
try {
60+
message.from = 'not allowed'
61+
expect(message.from).to.equal(sender)
62+
} catch (e) {
63+
expect(e).to.be.an('error')
64+
expect(e.toString()).to.equal(`TypeError: Cannot set property from of #<PubsubMessage> which has only a getter`)
65+
}
66+
})
67+
68+
it('data', () => {
69+
try {
70+
message.data = 'not allowed'
71+
expect(message.data).to.equal(data)
72+
} catch (e) {
73+
expect(e).to.be.an('error')
74+
expect(e.toString()).to.equal(`TypeError: Cannot set property data of #<PubsubMessage> which has only a getter`)
75+
}
76+
})
77+
78+
it('seqno', () => {
79+
try {
80+
message.seqno = 'not allowed'
81+
expect(message.seqno).to.equal(seqno)
82+
} catch (e) {
83+
expect(e).to.be.an('error')
84+
expect(e.toString()).to.equal(`TypeError: Cannot set property seqno of #<PubsubMessage> which has only a getter`)
85+
}
86+
})
87+
88+
it('topicIDs', () => {
89+
try {
90+
message.topicIDs = ['not allowed']
91+
expect(message.topicIDs[0]).to.equal(topicIDs[0])
92+
expect(message.topicIDs.length).to.equal(topicIDs.length)
93+
} catch (e) {
94+
expect(e).to.be.an('error')
95+
expect(e.toString()).to.equal(`TypeError: Cannot set property topicIDs of #<PubsubMessage> which has only a getter`)
96+
}
97+
})
8098
})
8199
})
82-
})
100+
}

0 commit comments

Comments
 (0)