Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
refactor: higher resolution of pubsub tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel committed Nov 17, 2021
1 parent a506259 commit 00d8105
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions test/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ describe('pubsub', function () {
})

it('should exchange non ascii data', function () {
const data = uint8ArrayFromString('你好世界\nzażółć\r\ngęślą\njaźń')
const topic = 'pubsub\nśnon\r\nascii'
const data = uint8ArrayFromString('你好世界 zażółć gęślą jaźń')
const topic = 'pubsub-non-ascii'

const subscriber = () => new Promise((resolve) => {
daemon2.api.pubsub.subscribe(topic, (msg) => {
Expand All @@ -126,7 +126,33 @@ describe('pubsub', function () {

it('should exchange binary data', function () {
const data = uint8ArrayFromString('a36161636179656162830103056164a16466666666f400010203040506070809', 'base16')
const topic = 'pubsub\nbinary\n'
const topic = 'pubsub-binary'

const subscriber = () => new Promise((resolve) => {
daemon2.api.pubsub.subscribe(topic, (msg) => {
expect(uint8ArrayEquals(data, msg.data)).to.be.true()
expect(msg).to.have.property('seqno')
expect(msg.seqno).to.be.an.instanceof(Uint8Array)
expect(msg).to.have.property('topicIDs').and.to.include(topic)
expect(msg).to.have.property('from', daemon1.api.peerId.id)
resolve()
})
})

const publisher = async () => {
await waitForTopicPeer(topic, daemon2.api.peerId, daemon1)
await daemon1.api.pubsub.publish(topic, data)
}

return Promise.all([
subscriber(),
publisher()
])
})

it('should exchange data over a topic with unicode and newlines', function () {
const data = uint8ArrayFromString('你好世界\nzażółć\r\ngęślą\njaźń')
const topic = 'pubsub\n你好世界\r\njaźń'

const subscriber = () => new Promise((resolve) => {
daemon2.api.pubsub.subscribe(topic, (msg) => {
Expand Down

0 comments on commit 00d8105

Please sign in to comment.