33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
// tests/infra/scan_cycle.test.js
|
|
import { describe, it, expect, vi } from 'vitest';
|
|
import { runDeviceScanCycle } from '../../lib/infra/scan_cycle.js';
|
|
|
|
function fakeRepo() {
|
|
return {
|
|
calls: [],
|
|
upsertScan: vi.fn(async r => r.length),
|
|
markAbsent: vi.fn(async () => 1),
|
|
prune: vi.fn(async () => 2)
|
|
};
|
|
}
|
|
|
|
describe('runDeviceScanCycle', () => {
|
|
it('scan→upsert→markAbsent→prune on a non-empty scan', async () => {
|
|
const repo = fakeRepo();
|
|
const scan = vi.fn(async () => [{ mac: 'aa:bb:cc:dd:ee:ff', ip: '1.2.3.4', vendor: 'x', randomized: false }]);
|
|
const res = await runDeviceScanCycle({ scan, repo });
|
|
expect(repo.upsertScan).toHaveBeenCalledOnce();
|
|
expect(repo.markAbsent).toHaveBeenCalledWith(['aa:bb:cc:dd:ee:ff']);
|
|
expect(repo.prune).toHaveBeenCalledOnce();
|
|
expect(res).toEqual({ seen: 1, pruned: 2 });
|
|
});
|
|
|
|
it('skips upsert/prune when the scan returns nothing', async () => {
|
|
const repo = fakeRepo();
|
|
const res = await runDeviceScanCycle({ scan: async () => [], repo });
|
|
expect(repo.upsertScan).not.toHaveBeenCalled();
|
|
expect(repo.prune).not.toHaveBeenCalled();
|
|
expect(res).toEqual({ seen: 0 });
|
|
});
|
|
});
|