|
3 | 3 |
|
4 | 4 | const expect = require('chai').expect
|
5 | 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 | 6 |
|
11 | 7 | // 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 |
13 | 9 | // final data types for the messages coming over the wire
|
14 | 10 |
|
15 |
| -describe('.pubsub-message', () => { |
16 |
| - if (!isNode) { |
17 |
| - return |
18 |
| - } |
| 11 | +const topicName = 'js-ipfs-api-tests' |
19 | 12 |
|
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 |
23 | 17 |
|
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 |
42 | 20 |
|
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 | + } |
45 | 26 |
|
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 |
53 | 29 | })
|
54 | 30 |
|
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 ] |
61 | 37 | }
|
62 |
| - }) |
63 |
| - |
64 |
| - it('seqno', () => { |
65 | 38 | 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) |
67 | 45 | } 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 |
70 | 47 | }
|
71 | 48 | })
|
72 | 49 |
|
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 | + }) |
80 | 98 | })
|
81 | 99 | })
|
82 |
| -}) |
| 100 | +} |
0 commit comments