feat(M06-D): 接入控制箱与Sub-1G门锁业务控制
This commit is contained in:
@@ -86,7 +86,7 @@ assert.equal(generateCommandId(1782120000000, 7), '1782120000007');
|
||||
assert.match(generateCommandId(), /^\d{13}$/);
|
||||
|
||||
const calls = [];
|
||||
let eventInsertCount = 0;
|
||||
const eventHashes = new Set();
|
||||
const service = new IotMessageService({
|
||||
async execute(sql, params) {
|
||||
calls.push({ sql, params });
|
||||
@@ -97,8 +97,10 @@ const service = new IotMessageService({
|
||||
}], []];
|
||||
}
|
||||
if (sql.includes('INSERT INTO qipai_iot_device_events')) {
|
||||
eventInsertCount += 1;
|
||||
return [{ affectedRows: eventInsertCount === 1 ? 1 : 2 }, []];
|
||||
const hash = params[7];
|
||||
const duplicate = eventHashes.has(hash);
|
||||
eventHashes.add(hash);
|
||||
return [{ affectedRows: duplicate ? 2 : 1 }, []];
|
||||
}
|
||||
return [{ affectedRows: 1, insertId: 81 }, []];
|
||||
}
|
||||
@@ -125,6 +127,30 @@ assert.equal(
|
||||
true
|
||||
);
|
||||
|
||||
const recordPayload = Buffer.from(JSON.stringify({
|
||||
DeviceID: 'BOX_001', event: 'record', type: 'card',
|
||||
state: 'open', content: 'CARD-PRIVATE-1234', battery: 9
|
||||
}));
|
||||
await service.handle('/devicesend/BOX_001', recordPayload);
|
||||
const recordInsert = calls.findLast((item) =>
|
||||
item.sql.includes('INSERT INTO qipai_iot_device_events')
|
||||
);
|
||||
assert.equal(recordInsert.params.some((value) =>
|
||||
typeof value === 'string' && value.includes('CARD-PRIVATE-1234')
|
||||
), false);
|
||||
assert.equal(calls.some((item) =>
|
||||
item.sql.includes('INSERT INTO qipai_device_alerts')
|
||||
&& item.params.includes('LOW_BATTERY')
|
||||
), true);
|
||||
|
||||
await service.handle('/devicesend/BOX_001', Buffer.from(JSON.stringify({
|
||||
DeviceID: 'BOX_001', id: '124', action: 'task', result: 'unconfirm'
|
||||
})));
|
||||
assert.equal(calls.some((item) =>
|
||||
item.sql.includes('INSERT INTO qipai_device_alerts')
|
||||
&& item.params.includes('DEVICE_UNCONFIRM')
|
||||
), true);
|
||||
|
||||
await assert.rejects(
|
||||
() => service.createCommand({
|
||||
tenantId: '7', assetId: '51', storeId: '11',
|
||||
|
||||
Reference in New Issue
Block a user