feat: Add Test for Connect API
This commit is contained in:
parent
5784e38fbb
commit
36bdb86343
@ -41,8 +41,6 @@ public:
|
||||
*/
|
||||
bool sendValue(String val, String poubelleID, String unit, bool full);
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief connect l'utilisateur a l'api et met a jour le token
|
||||
*
|
||||
@ -51,6 +49,11 @@ private:
|
||||
*/
|
||||
bool connect();
|
||||
|
||||
//TODO :: Check wifibegin avant
|
||||
|
||||
private:
|
||||
|
||||
|
||||
/**
|
||||
* @brief ID de l'utilisateur
|
||||
*
|
||||
|
@ -59,7 +59,8 @@ bool API::connect(){
|
||||
this->client->println();
|
||||
|
||||
|
||||
while (!client->available()) {}
|
||||
while (!client->available()) {
|
||||
}
|
||||
|
||||
String responce = "";
|
||||
while (client->available()) {
|
||||
@ -77,7 +78,10 @@ bool API::connect(){
|
||||
this->client->stop();
|
||||
|
||||
sortie = true;
|
||||
|
||||
if (JSONVar::stringify(JSONVar::parse(str)["code"]) == "400") {
|
||||
Serial.println("Failed to authenticate");
|
||||
return false;
|
||||
}
|
||||
return sortie;
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,8 @@ void setup() {
|
||||
Serial.begin(115200);
|
||||
RUN_TEST(TestWifiBeginConnected);
|
||||
RUN_TEST(TestWifiBeginNotConnected);
|
||||
RUN_TEST(TestConnectAPI);
|
||||
// RUN_TEST(TestConnectAPIFailed);
|
||||
|
||||
|
||||
UNITY_END();
|
||||
|
@ -3,5 +3,7 @@
|
||||
|
||||
void TestWifiBeginConnected();
|
||||
void TestWifiBeginNotConnected();
|
||||
void TestConnectAPI();
|
||||
// void TestConnectAPIFailed();
|
||||
|
||||
#endif
|
@ -2,6 +2,8 @@
|
||||
#include <unity.h>
|
||||
#include "API.h"
|
||||
|
||||
|
||||
//Testing WifiBegin function
|
||||
void TestWifiBeginConnected() {
|
||||
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");
|
||||
|
||||
}
|
||||
|
||||
//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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user