feat(devices): compute effective online status with stale heartbeat ttl

This commit is contained in:
2026-02-23 14:35:00 +00:00
parent 46c6294e48
commit 53ad0adead
7 changed files with 148 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
import { afterEach, describe, expect, test } from 'bun:test';
import { getBetterAuthBaseUrl, getFirstDefinedEnv } from '../utils/env';
import { getBetterAuthBaseUrl, getDeviceOnlineStaleSeconds, getFirstDefinedEnv } from '../utils/env';
const ORIGINAL_ENV = { ...process.env };
@@ -22,4 +22,25 @@ describe('env helpers', () => {
expect(getBetterAuthBaseUrl()).toBe('http://base-url:4000');
});
test('getDeviceOnlineStaleSeconds defaults to 30', () => {
delete process.env.DEVICE_ONLINE_STALE_SECONDS;
expect(getDeviceOnlineStaleSeconds()).toBe(30);
});
test('getDeviceOnlineStaleSeconds parses valid positive integer values', () => {
process.env.DEVICE_ONLINE_STALE_SECONDS = '45';
expect(getDeviceOnlineStaleSeconds()).toBe(45);
});
test('getDeviceOnlineStaleSeconds falls back to default on invalid values', () => {
process.env.DEVICE_ONLINE_STALE_SECONDS = '0';
expect(getDeviceOnlineStaleSeconds()).toBe(30);
process.env.DEVICE_ONLINE_STALE_SECONDS = '-2';
expect(getDeviceOnlineStaleSeconds()).toBe(30);
process.env.DEVICE_ONLINE_STALE_SECONDS = 'abc';
expect(getDeviceOnlineStaleSeconds()).toBe(30);
});
});