#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["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(); QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8()); QVERIFY(doc.isObject()); QVERIFY2(doc["items"].isArray(), "No parameter 'id' in response"); qDebug() << doc["items"].toArray()[0].toObject()["id"].toString(); QVERIFY2(doc["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(); QVERIFY(!response.isEmpty()); qDebug() << response; } QTEST_MAIN(UnitTest)