feat: Test_IOT #40

Merged
Clement merged 7 commits from feat/Test_IOT into master 2023-04-25 08:54:14 +00:00
5 changed files with 39 additions and 6 deletions
Showing only changes of commit 36bdb86343 - Show all commits

View File

@ -41,8 +41,6 @@ public:
*/ */
bool sendValue(String val, String poubelleID, String unit, bool full); bool sendValue(String val, String poubelleID, String unit, bool full);
private:
/** /**
* @brief connect l'utilisateur a l'api et met a jour le token * @brief connect l'utilisateur a l'api et met a jour le token
* *
@ -51,6 +49,11 @@ private:
*/ */
bool connect(); bool connect();
//TODO :: Check wifibegin avant
private:
/** /**
* @brief ID de l'utilisateur * @brief ID de l'utilisateur
* *

View File

@ -59,7 +59,8 @@ bool API::connect(){
this->client->println(); this->client->println();
while (!client->available()) {} while (!client->available()) {
}
String responce = ""; String responce = "";
while (client->available()) { while (client->available()) {
@ -77,7 +78,10 @@ bool API::connect(){
this->client->stop(); this->client->stop();
sortie = true; sortie = true;
if (JSONVar::stringify(JSONVar::parse(str)["code"]) == "400") {
Serial.println("Failed to authenticate");
return false;
}
return sortie; return sortie;
} }

View File

@ -8,6 +8,8 @@ void setup() {
Serial.begin(115200); Serial.begin(115200);
RUN_TEST(TestWifiBeginConnected); RUN_TEST(TestWifiBeginConnected);
RUN_TEST(TestWifiBeginNotConnected); RUN_TEST(TestWifiBeginNotConnected);
RUN_TEST(TestConnectAPI);
// RUN_TEST(TestConnectAPIFailed);
UNITY_END(); UNITY_END();

View File

@ -3,5 +3,7 @@
void TestWifiBeginConnected(); void TestWifiBeginConnected();
void TestWifiBeginNotConnected(); void TestWifiBeginNotConnected();
void TestConnectAPI();
// void TestConnectAPIFailed();
#endif #endif

View File

@ -2,6 +2,8 @@
#include <unity.h> #include <unity.h>
#include "API.h" #include "API.h"
//Testing WifiBegin function
void TestWifiBeginConnected() { void TestWifiBeginConnected() {
API* api = new API(USER_NAME, USER_PASSWORD, API_HOST); API* api = new API(USER_NAME, USER_PASSWORD, API_HOST);
@ -17,3 +19,23 @@ void TestWifiBeginNotConnected() {
TEST_ASSERT_EQUAL_MESSAGE(false, api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial2), "Wifi connected"); TEST_ASSERT_EQUAL_MESSAGE(false, api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial2), "Wifi connected");
} }
//Testing Connect function
void TestConnectAPI() {
API* api = new API(USER_NAME, USER_PASSWORD, API_HOST);
Serial1.begin(MONITOR_SPEED);
api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial1);
TEST_ASSERT_EQUAL_MESSAGE(true, api->connect(), "Not Connected");
}
// void TestConnectAPIFailed() {
// API* api = new API("Carl", "toto", API_HOST);
// Serial1.begin(MONITOR_SPEED);
// api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial1);
// TEST_ASSERT_EQUAL_MESSAGE(false, api->connect(), "Connected");
// }
//Testing SendValue function