Skip to content

Commit

Permalink
Merge pull request #3 from gnought/patch-1
Browse files Browse the repository at this point in the history
Added a missing dup field
  • Loading branch information
robertsLando authored Feb 11, 2020
2 parents 291d14d + cf8c1ba commit 2bcfdab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions packet.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function Packet (original, broker) {
this.payload = original.payload || Buffer.alloc(0)
this.qos = original.qos || 0
this.retain = original.retain || false
this.dup = original.dup || false
// [MQTT-2.3.1-5]
if (this.qos > 0 || this.cmd !== 'publish') {
// [MQTT-2.3.1-1]
Expand Down
20 changes: 20 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ test('Packet defaults - PUBLISH, QoS 0', function (t) {
t.equal(instance.topic, undefined)
t.deepEqual(instance.payload, Buffer.alloc(0))
t.equal(instance.qos, 0)
t.equal(instance.dup, false)
t.equal(instance.retain, false)
t.notOk(Object.prototype.hasOwnProperty.call(instance, 'messageId'))
t.end()
Expand All @@ -24,6 +25,7 @@ test('Packet defaults - PUBREL, QoS 0', function (t) {
t.equal(instance.topic, undefined)
t.deepEqual(instance.payload, Buffer.alloc(0))
t.equal(instance.qos, 0)
t.equal(instance.dup, false)
t.equal(instance.retain, false)
t.ok(Object.prototype.hasOwnProperty.call(instance, 'messageId'))
t.equal(instance.messageId, undefined)
Expand All @@ -38,12 +40,27 @@ test('Packet defaults - PUBLISH, QoS 1', function (t) {
t.equal(instance.topic, undefined)
t.deepEqual(instance.payload, Buffer.alloc(0))
t.equal(instance.qos, 1)
t.equal(instance.dup, false)
t.equal(instance.retain, false)
t.ok(Object.prototype.hasOwnProperty.call(instance, 'messageId'))
t.equal(instance.messageId, undefined)
t.end()
})

test('Packet defaults - PUBLISH, dup=true', function (t) {
var instance = new Packet({ dup: true })
t.equal(instance.cmd, 'publish')
t.equal(instance.brokerId, undefined)
t.equal(instance.brokerCounter, 0)
t.equal(instance.topic, undefined)
t.deepEqual(instance.payload, Buffer.alloc(0))
t.equal(instance.qos, 0)
t.equal(instance.dup, true)
t.equal(instance.retain, false)
t.equal(instance.messageId, undefined)
t.end()
})

test('Packet copies over most data', function (t) {
var original = {
cmd: 'pubrel',
Expand All @@ -52,6 +69,7 @@ test('Packet copies over most data', function (t) {
topic: 'hello',
payload: 'world',
qos: 2,
dup: true,
retain: true,
messageId: 24
}
Expand All @@ -63,6 +81,7 @@ test('Packet copies over most data', function (t) {
topic: 'hello',
payload: 'world',
qos: 2,
dup: true,
retain: true
}

Expand Down Expand Up @@ -94,6 +113,7 @@ test('Packet fills in broker data', function (t) {
topic: 'hello',
payload: 'world',
qos: 2,
dup: false,
retain: true
}

Expand Down

0 comments on commit 2bcfdab

Please sign in to comment.