upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tests/integration/test-market.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/integration/test-market.mjs')
-rw-r--r--tests/integration/test-market.mjs60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/integration/test-market.mjs b/tests/integration/test-market.mjs
new file mode 100644
index 0000000..20f062f
--- /dev/null
+++ b/tests/integration/test-market.mjs
@@ -0,0 +1,60 @@
1import { execSync } from 'child_process';
2
3const API_URL = `http://${process.env.TOLLGATE_IP || '10.192.45.1'}:2121`;
4
5function run(cmd) {
6 try { return execSync(cmd, { encoding: 'utf8', timeout: 15000 }); }
7 catch (e) { return e.stdout || null; }
8}
9
10function runJson(cmd) {
11 const out = run(cmd);
12 try { return out ? JSON.parse(out) : null; }
13 catch { return null; }
14}
15
16let passed = 0, failed = 0;
17function assert(cond, msg) {
18 if (cond) { console.log(` PASS: ${msg}`); passed++; }
19 else { console.log(` FAIL: ${msg}`); failed++; }
20}
21
22console.log('=== test-market (GET /market) ===\n');
23
24console.log('--- /market endpoint responds ---');
25{
26 const data = runJson(`curl -s --connect-timeout 5 ${API_URL}/market`);
27 assert(data !== null, '/market returns valid JSON');
28 assert(typeof data.count === 'number', `count is number (got ${data?.count})`);
29 assert(Array.isArray(data.entries), 'entries is array');
30}
31
32console.log('\n--- /market entry structure ---');
33{
34 const data = runJson(`curl -s --connect-timeout 5 ${API_URL}/market`);
35 if (data && data.entries && data.entries.length > 0) {
36 const e = data.entries[0];
37 assert(typeof e.bssid === 'string', `bssid is string (got ${e.bssid})`);
38 assert(typeof e.ssid === 'string', `ssid is string (got ${e.ssid})`);
39 assert(typeof e.rssi === 'number', `rssi is number (got ${e.rssi})`);
40 assert(typeof e.price_per_step === 'number', `price_per_step is number (got ${e.price_per_step})`);
41 assert(typeof e.step_size === 'number', `step_size is number (got ${e.step_size})`);
42 assert(typeof e.metric === 'string', `metric is string (got ${e.metric})`);
43 } else {
44 console.log(' SKIP: no entries found (scan may not have run yet)');
45 }
46}
47
48console.log('\n--- /market with no discovered TollGates ---');
49{
50 const data = runJson(`curl -s --connect-timeout 5 ${API_URL}/market`);
51 if (data && data.count === 0) {
52 assert(data.entries.length === 0, 'empty entries array when count=0');
53 console.log(' INFO: no nearby TollGates discovered yet (expected if only one board)');
54 } else if (data && data.count > 0) {
55 console.log(` INFO: ${data.count} nearby TollGate(s) discovered`);
56 }
57}
58
59console.log(`\n=== Results: ${passed} passed, ${failed} failed ===`);
60process.exit(failed > 0 ? 1 : 0);