|
@@ -0,0 +1,63 @@
|
|
|
+#include <atomic>
|
|
|
+
|
|
|
+#include <kbf.h>
|
|
|
+#include <kbf/nvs.h>
|
|
|
+#include <kbf/rtos.h>
|
|
|
+#include <kbf/wifi.h>
|
|
|
+#include <kbf/http/client.h>
|
|
|
+#include <kbf/web_service.h>
|
|
|
+
|
|
|
+#include "api/unpair_controller.h"
|
|
|
+
|
|
|
+#include <unity.h>
|
|
|
+#include <settings_manager.h>
|
|
|
+
|
|
|
+using namespace kbf;
|
|
|
+using namespace std;
|
|
|
+
|
|
|
+static const char *const url = "http://192.168.4.1/unpair";
|
|
|
+static const char *const ssid = "doorkeeper_test_master";
|
|
|
+static const char *const testPassword = "mg4drg9ss9e8t";
|
|
|
+static const char *const testPairingId = "1647daae-d4cf-4023-82e7-da57cb14106c";
|
|
|
+
|
|
|
+static rtos::EventGroup eventGroup;
|
|
|
+
|
|
|
+void unpairControllerMaster() {
|
|
|
+ nvs::erase();
|
|
|
+ SettingsManager::instance()->setPairingId(testPairingId);
|
|
|
+
|
|
|
+ auto ap = wifi::AP::create(ssid, testPassword);
|
|
|
+ ap->onDisconnect = {[](wifi::AP::STA &) { eventGroup.setBit(0); }};
|
|
|
+
|
|
|
+ auto sta = wifi::STA::create();
|
|
|
+ wifi::start(ap, sta);
|
|
|
+
|
|
|
+ auto webService = WebService();
|
|
|
+ webService.controller<UnpairController>();
|
|
|
+ webService.start();
|
|
|
+
|
|
|
+ eventGroup.waitForBit(0);
|
|
|
+
|
|
|
+ TEST_ASSERT_EQUAL_STRING("", SettingsManager::instance()->pairingId().c_str());
|
|
|
+
|
|
|
+ kbf::sleep(500);
|
|
|
+ webService.stop();
|
|
|
+ wifi::stop();
|
|
|
+}
|
|
|
+
|
|
|
+void unpairControllerSlave() {
|
|
|
+ auto sta = wifi::STA::create();
|
|
|
+ sta->onIp = {[](){ eventGroup.setBit(0); }};
|
|
|
+ wifi::start(sta);
|
|
|
+ sta->connect(ssid, testPassword);
|
|
|
+ eventGroup.waitForBit(0);
|
|
|
+
|
|
|
+ auto client = http::Client();
|
|
|
+ auto response = client.get(url);
|
|
|
+ TEST_ASSERT_EQUAL(200, response->status);
|
|
|
+
|
|
|
+ kbf::sleep(500);
|
|
|
+ wifi::stop();
|
|
|
+}
|
|
|
+
|
|
|
+TEST_CASE_MULTIPLE_DEVICES("UnpairController", "[controller]", unpairControllerMaster, unpairControllerSlave)
|