mirror of
https://gitlab.com/spaceti-app/integrations/acs/colnod-connector.git
synced 2026-07-12 14:00:39 +02:00
125 lines
4.2 KiB
C++
125 lines
4.2 KiB
C++
#include "unittest.h"
|
|
|
|
void UnitTest::loginSuccessfully()
|
|
{
|
|
RequestManager* testAccess = new RequestManager();
|
|
QJsonDocument config = testAccess->getConfig();
|
|
QSignalSpy spy(testAccess, SIGNAL(successLogin()));
|
|
testAccess->login(host, email, password);
|
|
spy.wait();
|
|
QVERIFY(spy.isValid());
|
|
QCOMPARE(spy.count(), 1);
|
|
QString json = testAccess->getResponse();
|
|
qDebug() << json;
|
|
QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
|
|
QVERIFY2(doc.object().value("id").isString(), "No parameter 'id' in response");
|
|
}
|
|
|
|
//POST request w/o datas
|
|
void UnitTest::getSubjects()
|
|
{
|
|
RequestManager* testAccess = new RequestManager();
|
|
// testAccess->login(host, email, password);
|
|
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
|
testAccess->getRequest("/SubjectManager/getSubjects");
|
|
spy.wait();
|
|
QVERIFY(spy.isValid());
|
|
QCOMPARE(spy.count(), 1);
|
|
QString json = testAccess->getResponse();
|
|
qDebug() << json;
|
|
QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
|
|
QVERIFY(doc.isObject());
|
|
QVERIFY2(doc.object().value("items").isArray(), "No parameter 'id' in response");
|
|
qDebug() << doc.object().value("items").toArray()[0].toObject()["id"].toString();
|
|
QVERIFY2(doc.object().value("items").toArray()[0].toObject()["id"].isString(), "ada");
|
|
|
|
}
|
|
|
|
void UnitTest::getTokens()
|
|
{
|
|
RequestManager* testAccess = new RequestManager();
|
|
// testAccess->login(host, email, password);
|
|
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
|
testAccess->getRequest("/TokenManager/getTokens");
|
|
QCOMPARE(spy.count(), 0);
|
|
spy.wait();
|
|
QVERIFY(spy.isValid());
|
|
QCOMPARE(spy.count(), 1);
|
|
qDebug() << testAccess->getResponse();
|
|
}
|
|
|
|
void UnitTest::getTokensOpenManager()
|
|
{
|
|
RequestManager* testAccess = new RequestManager();
|
|
// testAccess->login(host, email, password);
|
|
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
|
testAccess->getRequest("/OpenManager/getTokenSubject");
|
|
QCOMPARE(spy.count(), 0);
|
|
spy.wait();
|
|
QVERIFY(spy.isValid());
|
|
QCOMPARE(spy.count(), 1);
|
|
QString response = testAccess->getResponse();
|
|
qDebug() << response;
|
|
QVERIFY(!response.isEmpty());
|
|
}
|
|
|
|
void UnitTest::subjectJSONParser()
|
|
{
|
|
/*
|
|
QFile jsonData(QDir::current().filePath("subjects.json"));
|
|
|
|
if (!jsonData.open(QIODevice::ReadOnly)) {
|
|
qCritical() << "Couldn't open config file config.json" << QDir::current().filePath("subjects.json");
|
|
QCoreApplication::exit(-1);
|
|
return;
|
|
}
|
|
|
|
QJsonDocument doc = QJsonDocument::fromJson(jsonData.readAll());
|
|
QJsonObject obj = doc.object();
|
|
QJsonArray arr = obj["items"].toArray();
|
|
*/
|
|
|
|
RequestManager* testAccess = new RequestManager();
|
|
// testAccess->login(host, email, password);
|
|
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
|
testAccess->getRequest("/SubjectManager/getSubjects");
|
|
spy.wait();
|
|
QString response = testAccess->getResponse();
|
|
QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8());
|
|
QJsonArray arr = doc.object()["items"].toArray();
|
|
auto testSubject = new Subject();
|
|
testSubject->fromJSON(arr[1].toObject());
|
|
qDebug() << testSubject->getName() << " Size: " << arr.size();
|
|
QVERIFY(!testSubject->getName().isEmpty());
|
|
}
|
|
|
|
void UnitTest::tokenJSONParser()
|
|
{
|
|
RequestManager* testAccess = new RequestManager();
|
|
// testAccess->login(host, email, password);
|
|
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
|
testAccess->getRequest("/TokenManager/getTokens");
|
|
spy.wait();
|
|
QString response = testAccess->getResponse();
|
|
|
|
//TODO
|
|
/* QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8());
|
|
QJsonArray arr = doc.object()["items"].toArray();
|
|
auto testSubject = new Subject();
|
|
testSubject->fromJSON(arr[1].toObject());
|
|
qDebug() << testSubject->getName();
|
|
QVERIFY(!testSubject->getName().isEmpty());*/
|
|
QVERIFY(true);
|
|
|
|
}
|
|
|
|
void UnitTest::connectToDB()
|
|
{
|
|
DatabaseManager *db = new DatabaseManager("192.168.1.94", "deloitte", "postgres", "34rjkciea12");
|
|
QVERIFY(db->getOpened());
|
|
QVERIFY(true);
|
|
|
|
}
|
|
|
|
QTEST_MAIN(UnitTest)
|