battery: send alerts on channel "testowy" (index 2), not the pinned send channel
CI / build + unit (pull_request) Successful in 1m0s
CI / build + unit (pull_request) Successful in 1m0s
Owner request. BatteryAlertService reads new env BATTERY_ALERT_CHANNEL (default 2) at construction and passes it through MeshService.sendText, which gains an optional trailing channel argument defaulting to the pinned MESH_SEND_CHANNEL — every other sender is untouched. Threshold, cooldown, merged one-message-per-cycle format and @mentions unchanged.
This commit is contained in:
@@ -33,9 +33,10 @@ function makeService(
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
// defaults under test: threshold 20, cooldown 6 h
|
||||
// defaults under test: threshold 20, cooldown 6 h, channel 2 ("testowy")
|
||||
delete process.env.BATTERY_ALERT_THRESHOLD;
|
||||
delete process.env.BATTERY_ALERT_COOLDOWN_MS;
|
||||
delete process.env.BATTERY_ALERT_CHANNEL;
|
||||
});
|
||||
|
||||
describe('mention', () => {
|
||||
@@ -79,11 +80,13 @@ describe('BatteryAlertService check threshold', () => {
|
||||
|
||||
await svc.check();
|
||||
|
||||
// <= choice: exactly 20 qualifies too — both in ONE batched message
|
||||
// <= choice: exactly 20 qualifies too — both in ONE batched message, on the default channel 2
|
||||
expect(sendText).toHaveBeenCalledTimes(1);
|
||||
expect(sendText).toHaveBeenCalledWith(
|
||||
BROADCAST_ADDR,
|
||||
'⚠️ battery low: @!00000001 19%, @!00000002 20%',
|
||||
undefined,
|
||||
2,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -99,6 +102,8 @@ describe('BatteryAlertService check threshold', () => {
|
||||
expect(sendText).toHaveBeenCalledWith(
|
||||
BROADCAST_ADDR,
|
||||
'⚠️ battery low: @!00000001 50%',
|
||||
undefined,
|
||||
2,
|
||||
);
|
||||
} finally {
|
||||
delete process.env.BATTERY_ALERT_THRESHOLD;
|
||||
@@ -127,9 +132,31 @@ describe('BatteryAlertService check threshold', () => {
|
||||
expect(sendText.mock.calls[0]).toEqual([
|
||||
BROADCAST_ADDR,
|
||||
'⚠️ battery low: @!00000abc (A) 5%, @!00000def (B) 3%',
|
||||
undefined,
|
||||
2, // default channel "testowy" — not the pinned send channel (3)
|
||||
]);
|
||||
});
|
||||
|
||||
it('sends on a custom BATTERY_ALERT_CHANNEL when set', async () => {
|
||||
process.env.BATTERY_ALERT_CHANNEL = '5';
|
||||
const sendText = vi.fn(async (..._args: unknown[]) => 1);
|
||||
try {
|
||||
const svc = makeService([node(0xabc, 5)], sendText);
|
||||
|
||||
await svc.check();
|
||||
|
||||
expect(sendText).toHaveBeenCalledTimes(1);
|
||||
expect(sendText.mock.calls[0]).toEqual([
|
||||
BROADCAST_ADDR,
|
||||
'⚠️ battery low: @!00000abc 5%',
|
||||
undefined,
|
||||
5,
|
||||
]);
|
||||
} finally {
|
||||
delete process.env.BATTERY_ALERT_CHANNEL;
|
||||
}
|
||||
});
|
||||
|
||||
it('never throws when a send fails', async () => {
|
||||
const svc = makeService(
|
||||
[node(1, 5)],
|
||||
@@ -197,11 +224,11 @@ describe('BatteryAlertService check cooldown', () => {
|
||||
});
|
||||
|
||||
describe('BatteryAlertService check end-to-end (real MeshService)', () => {
|
||||
it('broadcasts the alert on the pinned send channel (index 3 by default)', async () => {
|
||||
it('broadcasts the alert on "testowy" (channel index 2), not the pinned send channel', async () => {
|
||||
const bridge = await startBridge();
|
||||
process.env.MESH_HOST = '127.0.0.1';
|
||||
process.env.MESH_PORT = String(bridge.port);
|
||||
delete process.env.MESH_SEND_CHANNEL; // default path: "test" (index 3)
|
||||
delete process.env.MESH_SEND_CHANNEL; // default pinned send channel is 3 — the alert must NOT ride it
|
||||
const mesh = new RealMeshService();
|
||||
try {
|
||||
mesh.onModuleInit();
|
||||
@@ -241,7 +268,7 @@ describe('BatteryAlertService check end-to-end (real MeshService)', () => {
|
||||
|
||||
await waitFor(() => readOutbound().length === 1);
|
||||
const pkt = readOutbound()[0];
|
||||
expect(pkt.channel).toBe(3); // "test" — never the primary channel (0)
|
||||
expect(pkt.channel).toBe(2); // "testowy" — not the pinned send channel (3) or primary (0)
|
||||
const data =
|
||||
pkt.payloadVariant?.case === 'decoded'
|
||||
? pkt.payloadVariant.value
|
||||
|
||||
Reference in New Issue
Block a user