fix #143
This commit is contained in:
parent
3023634a11
commit
60067f7c0b
@ -1392,6 +1392,11 @@ QPair<QList<RuleAction>, RuleEngine::RuleError> JsonTypes::verifyActions(const Q
|
||||
{
|
||||
QList<RuleAction> actions;
|
||||
QVariantList actionList = params.value("actions").toList();
|
||||
if (actionList.isEmpty()) {
|
||||
qCWarning(dcJsonRpc) << "Rule has no actions. This rule will do nothing.";
|
||||
return QPair<QList<RuleAction>, RuleEngine::RuleError>(actions, RuleEngine::RuleErrorInvalidRuleFormat);
|
||||
}
|
||||
|
||||
qCDebug(dcJsonRpc) << "unpacking actions:" << actionList;
|
||||
foreach (const QVariant &actionVariant, actionList) {
|
||||
QVariantMap actionMap = actionVariant.toMap();
|
||||
|
||||
@ -52,6 +52,8 @@ private slots:
|
||||
void addRemoveRules_data();
|
||||
void addRemoveRules();
|
||||
|
||||
void emptyRule();
|
||||
|
||||
void editRules_data();
|
||||
void editRules();
|
||||
|
||||
@ -394,6 +396,36 @@ void TestRestRules::addRemoveRules()
|
||||
nam->deleteLater();
|
||||
}
|
||||
|
||||
void TestRestRules::emptyRule()
|
||||
{
|
||||
// create add params for rule
|
||||
QVariantMap params;
|
||||
params.insert("name", QString());
|
||||
params.insert("actions", QVariantList());
|
||||
|
||||
QNetworkAccessManager *nam = new QNetworkAccessManager(this);
|
||||
QSignalSpy clientSpy(nam, SIGNAL(finished(QNetworkReply*)));
|
||||
|
||||
// Get rules and verify there is no rule added
|
||||
QNetworkRequest request = QNetworkRequest(QUrl(QString("http://localhost:3333/api/v1/rules")));
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "text/json");
|
||||
QNetworkReply *reply = nam->post(request, QJsonDocument::fromVariant(params).toJson(QJsonDocument::Compact));
|
||||
clientSpy.wait();
|
||||
QVERIFY2(clientSpy.count() == 1, "expected exactly 1 response from webserver");
|
||||
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
QCOMPARE(statusCode, 400);
|
||||
QByteArray data = reply->readAll();
|
||||
reply->deleteLater();
|
||||
|
||||
QJsonParseError error;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error);
|
||||
QCOMPARE(error.error, QJsonParseError::NoError);
|
||||
|
||||
QVERIFY2(jsonDoc.toVariant().toMap().contains("error"), "The error message is missing");
|
||||
QVERIFY2(jsonDoc.toVariant().toMap().value("error").toString() == "RuleErrorMissingParameter", "Wrong RuleError.");
|
||||
nam->deleteLater();
|
||||
}
|
||||
|
||||
void TestRestRules::editRules_data()
|
||||
{
|
||||
// RuleAction
|
||||
|
||||
@ -49,6 +49,8 @@ private slots:
|
||||
|
||||
void cleanup();
|
||||
|
||||
void emptyRule();
|
||||
|
||||
void addRemoveRules_data();
|
||||
void addRemoveRules();
|
||||
|
||||
@ -98,6 +100,15 @@ void TestRules::cleanup() {
|
||||
cleanupRules();
|
||||
}
|
||||
|
||||
void TestRules::emptyRule()
|
||||
{
|
||||
QVariantMap params;
|
||||
params.insert("name", QString());
|
||||
params.insert("actions", QVariantList());
|
||||
QVariant response = injectAndWait("Rules.AddRule", params);
|
||||
verifyRuleError(response, RuleEngine::RuleErrorMissingParameter);
|
||||
}
|
||||
|
||||
void TestRules::verifyRuleExecuted(const ActionTypeId &actionTypeId)
|
||||
{
|
||||
// Verify rule got executed
|
||||
|
||||
Reference in New Issue
Block a user