[verified] refactor: establish service and frontend boundaries
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { mkdtemp, readFile, writeFile } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import path from 'node:path'
|
||||
import { createSimAdminClient, normalizeInstance, summarizeInstanceSnapshot, redactInstance, loadConfig, addInstanceToConfig, updateInstanceInConfig, deleteInstanceFromConfig } from '../server/core.js'
|
||||
import { createSimAdminClient, normalizeInstance, summarizeInstanceSnapshot, redactInstance } from '../server/core.js'
|
||||
|
||||
test('normalizeInstance supports passwordless and password-protected instances without exposing password', () => {
|
||||
const open = normalizeInstance({ id: 'open-1', name: '开放设备', url: 'http://127.0.0.1:3000/' }, 0)
|
||||
@@ -66,6 +63,7 @@ test('snapshot summary exposes device-monitoring fields from stats, sms, data an
|
||||
assert.equal(snapshot.sim.present, true)
|
||||
assert.equal(snapshot.sim.phoneNumber, '13800138000')
|
||||
assert.equal(snapshot.network.operator, '中国移动')
|
||||
assert.equal(snapshot.network.registration, 'registered')
|
||||
assert.equal(snapshot.network.signal, -73)
|
||||
assert.equal(snapshot.network.accessTechnology, 'LTE')
|
||||
assert.equal(snapshot.sms.total, 12)
|
||||
@@ -83,28 +81,3 @@ test('snapshot summary exposes device-monitoring fields from stats, sms, data an
|
||||
assert.equal(snapshot.system.info.os, 'OpenWrt')
|
||||
assert.equal(snapshot.system.uptime, 3600)
|
||||
})
|
||||
|
||||
test('config store can add update and delete instances while persisting json', async () => {
|
||||
const dir = await mkdtemp(path.join(tmpdir(), 'multi-simadmin-'))
|
||||
const configPath = path.join(dir, 'config.json')
|
||||
await writeFile(configPath, JSON.stringify({ server: { host: '127.0.0.1', port: 9999 }, instances: [] }, null, 2))
|
||||
const config = await loadConfig({ configPath, defaultConfigPath: configPath })
|
||||
|
||||
const added = await addInstanceToConfig(config, { id: 'home-cpe', name: '家里 CPE', url: 'http://192.168.1.1/', auth: { password: 'pw' }, tags: ['home'] })
|
||||
assert.equal(added.id, 'home-cpe')
|
||||
assert.equal(added.url, 'http://192.168.1.1')
|
||||
assert.equal(config.instances.length, 1)
|
||||
|
||||
const updated = await updateInstanceInConfig(config, 'home-cpe', { name: '客厅 CPE', url: 'http://192.168.1.2', auth: { mode: 'none' }, description: 'main router' })
|
||||
assert.equal(updated.name, '客厅 CPE')
|
||||
assert.equal(updated.auth.password, '')
|
||||
|
||||
const persisted = JSON.parse(await readFile(configPath, 'utf8'))
|
||||
assert.equal(persisted.instances[0].name, '客厅 CPE')
|
||||
assert.equal(persisted.instances[0].url, 'http://192.168.1.2')
|
||||
|
||||
const removed = await deleteInstanceFromConfig(config, 'home-cpe')
|
||||
assert.equal(removed.id, 'home-cpe')
|
||||
assert.equal(config.instances.length, 0)
|
||||
assert.deepEqual(JSON.parse(await readFile(configPath, 'utf8')).instances, [])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user