feat(devices): compute effective online status with stale heartbeat ttl
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user