more API tests

This commit is contained in:
proddy
2021-09-21 18:06:36 +02:00
parent c3874d7c95
commit eba6324d18
2 changed files with 19 additions and 11 deletions

View File

@@ -482,8 +482,9 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) {
// first with nested
Mqtt::nested_format(1);
shell.invoke_command("call system publish");
shell.invoke_command("show mqtt");
// then without nested
// then without nested - single mode
Mqtt::nested_format(2);
shell.invoke_command("call system publish");
shell.invoke_command("show mqtt");
@@ -829,6 +830,9 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) {
if (command == "mqtt") {
shell.printfln(F("Testing MQTT..."));
Mqtt::ha_enabled(false);
Mqtt::enabled(true);
// add a boiler
add_device(0x08, 123); // Nefit Trendline
@@ -841,6 +845,8 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) {
uart_telegram("98 00 FF 00 01 A5 00 CF 21 2E 00 00 2E 24 03 25 03 03 01 03 25 00 C8 00 00 11 01 03"); // without CRC
uart_telegram_withCRC("98 00 FF 00 01 A5 00 CF 21 2E 00 00 2E 24 03 25 03 03 01 03 25 00 C8 00 00 11 01 03 13"); // with CRC
shell.invoke_command("call system publish");
shell.invoke_command("show mqtt");
shell.loop_all();
char boiler_topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
@@ -853,11 +859,11 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) {
strcpy(thermostat_topic, "ems-esp/thermostat");
strcpy(system_topic, "ems-esp/system");
EMSESP::mqtt_.incoming(boiler_topic, ""); // test if ignore empty payloads // invalid format
EMSESP::mqtt_.incoming(boiler_topic, ""); // test if ignore empty payloads
EMSESP::mqtt_.incoming(boiler_topic, "12345"); // invalid format
EMSESP::mqtt_.incoming("bad_topic", "12345"); // no matching topic
EMSESP::mqtt_.incoming(boiler_topic, "{\"cmd\":\"garbage\",\"data\":22.52}"); // should report error
EMSESP::mqtt_.incoming(boiler_topic, "12345"); // error: invalid format
EMSESP::mqtt_.incoming("bad_topic", "12345"); // error: no matching topic
EMSESP::mqtt_.incoming(boiler_topic, "{\"cmd\":\"garbage\",\"data\":22.52}"); // error: should report error
EMSESP::mqtt_.incoming(boiler_topic, "{\"cmd\":\"comfort\",\"data\":\"eco\"}");
EMSESP::mqtt_.incoming(boiler_topic, "{\"cmd\":\"wwactivated\",\"data\":\"1\"}"); // with quotes
@@ -953,16 +959,18 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) {
run_test("general");
AsyncWebServerRequest request;
request.url("/api/boiler/id");
EMSESP::webAPIService.webAPIService_get(&request);
// GET
request.url("/api/thermostat");
EMSESP::webAPIService.webAPIService_get(&request);
request.url("/api/thermostat/info");
EMSESP::webAPIService.webAPIService_get(&request);
// these next 2 should fail
request.url("/api/boiler/id");
EMSESP::webAPIService.webAPIService_get(&request);
request.url("/api/thermostat/hamode");
EMSESP::webAPIService.webAPIService_get(&request);
// GET
request.method(HTTP_GET);
request.url("/api/thermostat/seltemp");
EMSESP::webAPIService.webAPIService_get(&request);

View File

@@ -33,13 +33,13 @@ namespace emsesp {
// #define EMSESP_DEBUG_DEFAULT "general"
// #define EMSESP_DEBUG_DEFAULT "boiler"
// #define EMSESP_DEBUG_DEFAULT "mqtt2"
// #define EMSESP_DEBUG_DEFAULT "mqtt_nested"
#define EMSESP_DEBUG_DEFAULT "mqtt_nested"
// #define EMSESP_DEBUG_DEFAULT "ha"
// #define EMSESP_DEBUG_DEFAULT "board_profile"
// #define EMSESP_DEBUG_DEFAULT "shower_alert"
// #define EMSESP_DEBUG_DEFAULT "310"
// #define EMSESP_DEBUG_DEFAULT "render"
#define EMSESP_DEBUG_DEFAULT "api"
// #define EMSESP_DEBUG_DEFAULT "api"
// #define EMSESP_DEBUG_DEFAULT "crash"
class Test {