Support soundbox firmware MQTT topics
This commit is contained in:
@ -142,16 +142,16 @@ async function pullQf100Config(serialNumber, label) {
|
||||
assert(config["error-code"] === 0, `${label} config error-code must be 0`);
|
||||
assert(config.mqtt?.["broker-ip"], `${label} config must include mqtt.broker-ip`);
|
||||
assert(config.mqtt?.["broker-port"], `${label} config must include mqtt.broker-port`);
|
||||
assert(config.mqtt?.["subscribe-topic"]?.includes("/downlink/qf100"), `${label} must subscribe qf100 topic`);
|
||||
assert(config.mqtt?.["subscribe-topic"] === `soundbox/${serialNumber}/down`, `${label} must subscribe soundbox SN topic`);
|
||||
return config;
|
||||
}
|
||||
|
||||
async function waitForQf100PaymentMessage(deviceId) {
|
||||
async function waitForQf100PaymentMessage(deviceId, serialNumber) {
|
||||
for (let i = 0; i < 20; i += 1) {
|
||||
const data = await reqAdmin(`/admin/devices/${deviceId}/mqtt-messages?direction=downlink&message_type=payment_success&limit=10`, {
|
||||
_label: `GET /admin/devices/:id/mqtt-messages attempt ${i + 1}`
|
||||
});
|
||||
const found = data.messages?.find((message) => message.topic === `devices/${deviceId}/downlink/qf100`);
|
||||
const found = data.messages?.find((message) => message.topic === `soundbox/${serialNumber}/down`);
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
@ -196,7 +196,7 @@ async function triggerStaticPayment({ bundle, ts }) {
|
||||
_label: "POST /integrations/qris/callback static paid"
|
||||
});
|
||||
|
||||
const message = await waitForQf100PaymentMessage(bundle.device.id);
|
||||
const message = await waitForQf100PaymentMessage(bundle.device.id, bundle.device.serial_number);
|
||||
assert(message.payload_json?.header?.category === 1, "QF100 payment payload header.category must be 1");
|
||||
assert(message.payload_json?.data?.["pay-amount"] === 15000, "QF100 payment payload pay-amount must match");
|
||||
return message;
|
||||
@ -248,8 +248,8 @@ async function main() {
|
||||
|
||||
const staticConfig = await pullQf100Config(STATIC_SN, "static");
|
||||
const dynamicConfig = await pullQf100Config(DYNAMIC_SN, "dynamic");
|
||||
assert(staticConfig.mqtt["client-id"] === staticBundle.device.id, "static client-id must match device id");
|
||||
assert(dynamicConfig.mqtt["client-id"] === dynamicBundle.device.id, "dynamic client-id must match device id");
|
||||
assert(staticConfig.mqtt["client-id"] === `soundbox-${STATIC_SN}`, "static client-id must match serial number");
|
||||
assert(dynamicConfig.mqtt["client-id"] === `soundbox-${DYNAMIC_SN}`, "dynamic client-id must match serial number");
|
||||
|
||||
const staticPaymentMessage = await triggerStaticPayment({ bundle: staticBundle, ts });
|
||||
const dynamicQr = await triggerDynamicMqttQr({ bundle: dynamicBundle, ts });
|
||||
|
||||
Reference in New Issue
Block a user