Skip to content

Commit 1b8f258

Browse files
committed
fix: topic flag
1 parent 2418189 commit 1b8f258

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/service-mqtt.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class ServiceMQTT extends Service {
8181
get topics() {
8282
return Object.values(this.endpoints)
8383
.filter(e => e.topic)
84-
.map(e => e.name);
84+
.map(e => e.topic);
8585
}
8686

8787
/**

src/topic-endpoint.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export class TopicEndpoint extends SendReceiveEndpoint {
44
constructor(name, owner, options) {
55
super(name, owner, options);
66

7-
if (options.topic) {
7+
if (typeof options.topic === "string") {
88
this._topic = options.topic;
99
}
1010
}

tests/mqtt-ava.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ test("endpoint factory", async t => {
1313
const mqtt = await sp.declareService({
1414
type: ServiceMQTT,
1515
endpoints: {
16-
s1: { topic: "s1", connected: r1 }
16+
s1: { topic: true, connected: r1 },
17+
s2: { topic: "s2b", connected: r1 }
1718
}
1819
});
1920

2021
t.is(mqtt.endpoints["s1"].name, "s1");
22+
t.is(mqtt.endpoints["s2"].name, "s2");
2123
t.true(mqtt.endpoints["s1"] instanceof TopicEndpoint);
22-
t.deepEqual(mqtt.topics, ["s1"]);
24+
t.deepEqual(mqtt.topics, ["s1", "s2b"]);
2325
});

0 commit comments

Comments
 (0)