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

Commit 44c16e9

Browse files
committed
feat: move pubsub message tests to here, they are not interface-ipfs-core
1 parent 01044a1 commit 44c16e9

File tree

2 files changed

+87
-26
lines changed

2 files changed

+87
-26
lines changed

test/interface-ipfs-core/pubsub-message.spec.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

test/ipfs-api/pubsub-message.spec.js

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

0 commit comments

Comments
 (0)