summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Zhineng <[email protected]>2025-07-02 20:57:59 +0800
committerLi Zhineng <[email protected]>2025-07-02 20:57:59 +0800
commit5570c76f16f8069f3a81044784842f6dbd1aaf66 (patch)
treeb341fbcfa0058b6d22330dc6493fafb4a5345f53
parentfd5876743c2070a5259c36110e7e02f80ed80458 (diff)
downloadserver-5570c76f16f8069f3a81044784842f6dbd1aaf66.tar.gz
server-5570c76f16f8069f3a81044784842f6dbd1aaf66.zip
stub eagle online handler
-rw-r--r--server.mjs14
-rw-r--r--server.test.mjs13
2 files changed, 27 insertions, 0 deletions
diff --git a/server.mjs b/server.mjs
index 2475442..b431d1e 100644
--- a/server.mjs
+++ b/server.mjs
@@ -35,6 +35,9 @@ const eagleController = (req, res) => {
case 'eagle/GET/genId':
eagleGenIdController(req, res)
break
+ case 'eagle/GET/online':
+ eagleOnlineController(req, res)
+ break
default:
notFoundController(req, res)
break
@@ -66,6 +69,17 @@ const eagleGenIdController = (req, res) => {
}))
}
+const eagleOnlineController = (req, res) => {
+ res.writeHead(200, { 'Content-Type': 'application/json' })
+ res.end(JSON.stringify({
+ status: 200,
+ data: {
+ snow: 1, // Air quality monitor
+ eagle: 1 // The AIRMX Pro unit
+ }
+ }))
+}
+
const exchangeController = (req, res) => {
const [, query] = req.url.split('?')
const params = new URLSearchParams(query)
diff --git a/server.test.mjs b/server.test.mjs
index 1e44083..619d29f 100644
--- a/server.test.mjs
+++ b/server.test.mjs
@@ -142,6 +142,19 @@ test('device registration endpoint returns not found if path is not supported',
assert.strictEqual(res.status, 404)
})
+test('device status endpoint', async () => {
+ const params = new URLSearchParams({
+ source: 5,
+ reqid: '0000000000',
+ eagleId: 1,
+ path: 'eagle/GET/online',
+ params: '{}',
+ sig: '00000000000000000000000000000000'
+ })
+ const res = await fetch(`${baseUrl}/eagle?${params.toString()}`)
+ assert.strictEqual(res.status, 200)
+})
+
test('exchange endpoint', async () => {
const stubMacAddress = '0000000000'
const stubKey = '00000000000000000000000000000000'