forked from ondra/colnod-connector
Unit test for testing RequestManager Class
This commit is contained in:
parent
870f5487ba
commit
bcb927eda1
66
test/unitTests/UnitTest.cpp
Normal file
66
test/unitTests/UnitTest.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
#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)
|
||||
26
test/unitTests/unittest.h
Normal file
26
test/unitTests/unittest.h
Normal file
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
#include <QSignalSpy>
|
||||
#include <requestmanager.h>
|
||||
|
||||
|
||||
class UnitTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
|
||||
void loginSuccessfully();
|
||||
|
||||
|
||||
void getTokens();
|
||||
void getTokensOpenManager();
|
||||
void getSubjects();
|
||||
|
||||
private:
|
||||
// QString host = "https://localhost:8080"; //colnod server (ssh -L 8080:192.168.254.11:8443 penta-master)
|
||||
QString host = "https://192.168.1.3:8443"; //local testing server
|
||||
QString password = "spaceti1";
|
||||
QString email = "spaceti";
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user