Skip to content

Commit

Permalink
Test Case updates
Browse files Browse the repository at this point in the history
  • Loading branch information
NuwanJ-RhinoPartners committed Sep 1, 2023
1 parent 8624ac7 commit 35cea75
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class MQTTRouter {
/**
* Method for starting the MQTT handler
*/
start = () => {
start = (callback: Function) => {
this._mqttClient.on('connect', () => {
console.log('MQTT_Connecting...\n');
this.setup();
Expand All @@ -153,6 +153,10 @@ export class MQTTRouter {
}
this._publishQueue.start();
console.log(`MQTT_Router: Connected to the channel '${channel}'\n`);

if (callback) {
callback(`MQTT_Router: Connected to the channel ${channel}`);
}
});

this._mqttClient.on('error', (err) => {
Expand Down
32 changes: 28 additions & 4 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ const SAMPLE_ROUTES = [
fallbackRetainHandler: () => {
console.log('Fallback method');
}
},
{
topic: 'quite',
allowRetained: true,
subscribe: true,
publish: false,
type: 'String',
handler: (msg) => {
try {
process.exit(0);
} catch (err) {
console.log('Handler error:', err);
}
},
fallbackRetainHandler: () => {
console.log('Fallback method');
}
}
];

Expand All @@ -73,8 +90,6 @@ router = new MQTTRouter(
SAMPLE_ON_ERROR_FN
);

router.start();

const samplePublishMessages = [
{
topic: 'sample-2',
Expand All @@ -99,9 +114,18 @@ const samplePublishMessages = [
{
topic: 'sample-2',
data: 'Sample Data 6'
},
{
topic: 'quite',
data: 'End the test'
}
];

samplePublishMessages.forEach((element) => {
router.pushToPublishQueue(element.topic, element.data);
router.start((response) => {
console.log(response);
samplePublishMessages.forEach((element) => {
console.log('Publishing', element.topic);
console.log(element.data);
router.pushToPublishQueue(element.topic, element.data);
});
});

0 comments on commit 35cea75

Please sign in to comment.