|
1 |
| -import { PROPERTY } from '../../../es6/enums'; |
| 1 | +import {PROPERTY} from '../../../es6/enums'; |
2 | 2 | import {PACKET_TYPE} from '../../enums';
|
3 | 3 | import {PacketConnect} from '../connect';
|
4 | 4 |
|
@@ -140,3 +140,77 @@ test('can remove will', () => {
|
140 | 140 | expect(packet.wt).toBe(undefined);
|
141 | 141 | expect(packet.wp).toBe(undefined);
|
142 | 142 | });
|
| 143 | + |
| 144 | +test('can manipulate multiple properties simultaneously', () => { |
| 145 | + const packet = PacketConnect.create(5, 0, 30, {}, 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'); |
| 146 | + |
| 147 | + expect(packet.qualityOfService()).toBe(0); |
| 148 | + packet.setQualityOfService(2); |
| 149 | + expect(packet.qualityOfService()).toBe(2); |
| 150 | + |
| 151 | + expect(packet.usr).toBe(undefined); |
| 152 | + packet.setUserName('foo'); |
| 153 | + expect(packet.qualityOfService()).toBe(2); |
| 154 | + expect(packet.usr).toBe('foo'); |
| 155 | + |
| 156 | + expect(packet.pwd).toBe(undefined); |
| 157 | + packet.setPassword(Buffer.from([1, 2])); |
| 158 | + expect(packet.pwd).toEqual(Buffer.from([1, 2])); |
| 159 | + expect(packet.qualityOfService()).toBe(2); |
| 160 | + expect(packet.usr).toBe('foo'); |
| 161 | + |
| 162 | + expect(packet.cleanStart()).toBe(false); |
| 163 | + packet.setCleanStart(true); |
| 164 | + expect(packet.cleanStart()).toBe(true); |
| 165 | + expect(packet.pwd).toEqual(Buffer.from([1, 2])); |
| 166 | + expect(packet.qualityOfService()).toBe(2); |
| 167 | + expect(packet.usr).toBe('foo'); |
| 168 | + |
| 169 | + expect(packet.willFlag()).toBe(false); |
| 170 | + expect(packet.willRetain()).toBe(false); |
| 171 | + expect(packet.willQos()).toBe(0); |
| 172 | + packet.setWill(Buffer.from([25]), 't', {}, 0, false); |
| 173 | + expect(packet.willFlag()).toBe(true); |
| 174 | + expect(packet.willRetain()).toBe(false); |
| 175 | + expect(packet.willQos()).toBe(0); |
| 176 | + expect(packet.cleanStart()).toBe(true); |
| 177 | + expect(packet.pwd).toEqual(Buffer.from([1, 2])); |
| 178 | + expect(packet.qualityOfService()).toBe(2); |
| 179 | + expect(packet.usr).toBe('foo'); |
| 180 | + |
| 181 | + packet.removePassword(); |
| 182 | + expect(packet.willFlag()).toBe(true); |
| 183 | + expect(packet.willRetain()).toBe(false); |
| 184 | + expect(packet.willQos()).toBe(0); |
| 185 | + expect(packet.cleanStart()).toBe(true); |
| 186 | + expect(packet.pwd).toBe(undefined); |
| 187 | + expect(packet.qualityOfService()).toBe(2); |
| 188 | + expect(packet.usr).toBe('foo'); |
| 189 | + |
| 190 | + packet.removeUserName(); |
| 191 | + expect(packet.willFlag()).toBe(true); |
| 192 | + expect(packet.willRetain()).toBe(false); |
| 193 | + expect(packet.willQos()).toBe(0); |
| 194 | + expect(packet.cleanStart()).toBe(true); |
| 195 | + expect(packet.pwd).toBe(undefined); |
| 196 | + expect(packet.qualityOfService()).toBe(2); |
| 197 | + expect(packet.usr).toBe(undefined); |
| 198 | + |
| 199 | + packet.removeWill() |
| 200 | + expect(packet.willFlag()).toBe(false); |
| 201 | + expect(packet.willRetain()).toBe(false); |
| 202 | + expect(packet.willQos()).toBe(0); |
| 203 | + expect(packet.cleanStart()).toBe(true); |
| 204 | + expect(packet.pwd).toBe(undefined); |
| 205 | + expect(packet.qualityOfService()).toBe(2); |
| 206 | + expect(packet.usr).toBe(undefined); |
| 207 | + |
| 208 | + packet.setCleanStart(false); |
| 209 | + expect(packet.willFlag()).toBe(false); |
| 210 | + expect(packet.willRetain()).toBe(false); |
| 211 | + expect(packet.willQos()).toBe(0); |
| 212 | + expect(packet.cleanStart()).toBe(false); |
| 213 | + expect(packet.pwd).toBe(undefined); |
| 214 | + expect(packet.qualityOfService()).toBe(2); |
| 215 | + expect(packet.usr).toBe(undefined); |
| 216 | +}); |
0 commit comments