mirror of https://github.com/nymea/nymea.git
add rule tests
parent
79e0ff2dd6
commit
c0b19c168c
|
|
@ -54,6 +54,8 @@ private:
|
|||
|
||||
private slots:
|
||||
void getRules();
|
||||
void invalidMethod();
|
||||
void invalidPath();
|
||||
|
||||
void checkOptionCall();
|
||||
|
||||
|
|
@ -207,6 +209,46 @@ void TestRestRules::getRules()
|
|||
}
|
||||
}
|
||||
|
||||
void TestRestRules::invalidMethod()
|
||||
{
|
||||
QNetworkAccessManager nam;
|
||||
QSignalSpy clientSpy(&nam, SIGNAL(finished(QNetworkReply*)));
|
||||
|
||||
QNetworkRequest request;
|
||||
request.setUrl(QUrl("http://localhost:3333/api/v1/rules"));
|
||||
QNetworkReply *reply = nam.sendCustomRequest(request, "TRACE");
|
||||
|
||||
clientSpy.wait();
|
||||
QVERIFY2(clientSpy.count() == 1, "expected exactly 1 response from webserver");
|
||||
|
||||
bool ok = false;
|
||||
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(&ok);
|
||||
QVERIFY2(ok, "Could not convert statuscode from response to int");
|
||||
QCOMPARE(statusCode, 405);
|
||||
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
||||
void TestRestRules::invalidPath()
|
||||
{
|
||||
QNetworkAccessManager nam;
|
||||
QSignalSpy clientSpy(&nam, SIGNAL(finished(QNetworkReply*)));
|
||||
|
||||
QNetworkRequest request;
|
||||
request.setUrl(QUrl("http://localhost:3333/api/v1/rules/" + QUuid::createUuid().toString() + "/" + QUuid::createUuid().toString()));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
|
||||
clientSpy.wait();
|
||||
QVERIFY2(clientSpy.count() == 1, "expected exactly 1 response from webserver");
|
||||
|
||||
bool ok = false;
|
||||
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(&ok);
|
||||
QVERIFY2(ok, "Could not convert statuscode from response to int");
|
||||
QCOMPARE(statusCode, 404);
|
||||
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
||||
void TestRestRules::checkOptionCall()
|
||||
{
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:3333/api/v1/rules")));
|
||||
|
|
|
|||
|
|
@ -62,6 +62,8 @@ private slots:
|
|||
void executeRuleActions_data();
|
||||
void executeRuleActions();
|
||||
|
||||
void findRule();
|
||||
|
||||
void removeInvalidRule();
|
||||
|
||||
void loadStoreConfig();
|
||||
|
|
@ -848,6 +850,31 @@ void TestRules::executeRuleActions()
|
|||
verifyRuleError(response);
|
||||
}
|
||||
|
||||
void TestRules::findRule()
|
||||
{
|
||||
// ADD rule
|
||||
QVariantMap params = validIntStateBasedRule("Executeable", true, true).toMap();
|
||||
QVariant response = injectAndWait("Rules.AddRule", params);
|
||||
verifyRuleError(response);
|
||||
|
||||
RuleId ruleId = RuleId(response.toMap().value("params").toMap().value("ruleId").toString());
|
||||
QVERIFY(!ruleId.isNull());
|
||||
|
||||
params.clear();
|
||||
params.insert("deviceId", m_mockDeviceId);
|
||||
response = injectAndWait("Rules.FindRules", params);
|
||||
|
||||
QCOMPARE(response.toMap().value("params").toMap().value("ruleIds").toList().count(), 1);
|
||||
QCOMPARE(response.toMap().value("params").toMap().value("ruleIds").toList().first().toString(), ruleId.toString());
|
||||
|
||||
// REMOVE rule
|
||||
QVariantMap removeParams;
|
||||
removeParams.insert("ruleId", ruleId);
|
||||
response = injectAndWait("Rules.RemoveRule", removeParams);
|
||||
verifyRuleError(response);
|
||||
|
||||
}
|
||||
|
||||
void TestRules::removeInvalidRule()
|
||||
{
|
||||
QVariantMap params;
|
||||
|
|
|
|||
Loading…
Reference in New Issue