diff options
| author | Li Zhineng <[email protected]> | 2025-07-01 15:11:09 +0800 |
|---|---|---|
| committer | Li Zhineng <[email protected]> | 2025-07-01 15:11:09 +0800 |
| commit | 4fd7219f6000c718432cb2107142867c5ca587b8 (patch) | |
| tree | dac41afe90dae0d9bec709ba85a2cf49ab3b19b2 /server.test.mjs | |
| parent | 7beec630f784d72d21ee621700df42aaa4f4b498 (diff) | |
| download | server-4fd7219f6000c718432cb2107142867c5ca587b8.tar.gz server-4fd7219f6000c718432cb2107142867c5ca587b8.zip | |
exchange endpoint
Diffstat (limited to 'server.test.mjs')
| -rw-r--r-- | server.test.mjs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/server.test.mjs b/server.test.mjs index f59f09b..5e01355 100644 --- a/server.test.mjs +++ b/server.test.mjs @@ -10,6 +10,12 @@ const port = 8090 const baseUrl = `http://${hostname}:${port}` let server = null +const createDevice = async (mac, key) => { + const response = await fetch(`${baseUrl}/eagle?mac=${mac}&key=${key}`) + const data = await response.json() + return data.data.eagleId +} + before(() => new Promise((resolve, reject) => { const nodeBinary = process.argv[0] server = spawn(nodeBinary, ['server.mjs'], { @@ -111,3 +117,25 @@ test('device registration endpoint returns bad request if missing encryption key assert.fail(`HTTP request failed: ${err.message}`) }) }) + +test('exchange endpoint', async () => { + const stubMacAddress = '00:00:00:00:00' + const stubKey = '00000000000000000000000000000000' + + const deviceId = await createDevice(stubMacAddress, stubKey) + const res = await fetch(`${baseUrl}/exchange?device=${deviceId}`) + assert.strictEqual(res.status, 200) + + const data = await res.json() + assert.strictEqual(data.key, stubKey) +}) + +test('exchange endpoint returns unprocessable content when device id is missing', async () => { + const res = await fetch(`${baseUrl}/exchange`) + assert.strictEqual(res.status, 422) +}) + +test('exchange endpoint returns not found when device does not exist', async () => { + const res = await fetch(`${baseUrl}/exchange?device=9999`) + assert.strictEqual(res.status, 404) +}) |
