|
5 | 5 | from rest_framework.test import APITestCase
|
6 | 6 |
|
7 | 7 | from openforms.accounts.tests.factories import SuperUserFactory, UserFactory
|
| 8 | +from openforms.variables.constants import FormVariableDataTypes, FormVariableSources |
8 | 9 |
|
| 10 | +from ..constants import LogicActionTypes |
9 | 11 | from ..models import FormLogic
|
10 | 12 | from .factories import (
|
11 | 13 | FormFactory,
|
@@ -1286,3 +1288,166 @@ def test_performance_validation_bulk_create_data(self):
|
1286 | 1288 |
|
1287 | 1289 | self.assertEqual(response.status_code, status.HTTP_200_OK)
|
1288 | 1290 | self.assertEqual(FormLogic.objects.count(), 2)
|
| 1291 | + |
| 1292 | + def test_create_rule_with_evaluate_dmn_action(self): |
| 1293 | + user = SuperUserFactory.create(username="test", password="test") |
| 1294 | + form = FormFactory.create() |
| 1295 | + FormStepFactory.create( |
| 1296 | + form=form, |
| 1297 | + form_definition__configuration={ |
| 1298 | + "components": [ |
| 1299 | + { |
| 1300 | + "type": "number", |
| 1301 | + "key": "age", |
| 1302 | + }, |
| 1303 | + { |
| 1304 | + "type": "number", |
| 1305 | + "key": "income", |
| 1306 | + }, |
| 1307 | + ] |
| 1308 | + }, |
| 1309 | + ) |
| 1310 | + FormVariableFactory.create( |
| 1311 | + form=form, |
| 1312 | + source=FormVariableSources.user_defined, |
| 1313 | + key="canApply", |
| 1314 | + data_type=FormVariableDataTypes.boolean, |
| 1315 | + ) |
| 1316 | + |
| 1317 | + form_logic_data = [ |
| 1318 | + { |
| 1319 | + "form": f"http://testserver{reverse('api:form-detail', kwargs={'uuid_or_slug': form.uuid})}", |
| 1320 | + "order": 0, |
| 1321 | + "is_advanced": True, |
| 1322 | + "json_logic_trigger": True, |
| 1323 | + "actions": [ |
| 1324 | + { |
| 1325 | + "action": { |
| 1326 | + "type": LogicActionTypes.evaluate_dmn, |
| 1327 | + "config": { |
| 1328 | + "plugin_id": "camunda7", |
| 1329 | + "decision_definition_id": "some-id", |
| 1330 | + "decision_definition_version": "1", |
| 1331 | + "input_mapping": { |
| 1332 | + "age": "ageDMN", |
| 1333 | + "income": "incomeDMN", |
| 1334 | + }, |
| 1335 | + "output_mapping": {"canApply": "canApplyDMN"}, |
| 1336 | + }, |
| 1337 | + }, |
| 1338 | + } |
| 1339 | + ], |
| 1340 | + } |
| 1341 | + ] |
| 1342 | + |
| 1343 | + self.client.force_authenticate(user=user) |
| 1344 | + url = reverse("api:form-logic-rules", kwargs={"uuid_or_slug": form.uuid}) |
| 1345 | + response = self.client.put(url, data=form_logic_data) |
| 1346 | + |
| 1347 | + self.assertEqual(status.HTTP_200_OK, response.status_code) |
| 1348 | + |
| 1349 | + new_rule = FormLogic.objects.get(form=form, order=0) |
| 1350 | + |
| 1351 | + self.assertEqual( |
| 1352 | + new_rule.actions[0]["action"]["type"], LogicActionTypes.evaluate_dmn |
| 1353 | + ) |
| 1354 | + self.assertEqual( |
| 1355 | + new_rule.actions[0]["action"]["config"], |
| 1356 | + { |
| 1357 | + "plugin_id": "camunda7", |
| 1358 | + "decision_definition_id": "some-id", |
| 1359 | + "decision_definition_version": "1", |
| 1360 | + "input_mapping": {"age": "ageDMN", "income": "incomeDMN"}, |
| 1361 | + "output_mapping": {"canApply": "canApplyDMN"}, |
| 1362 | + }, |
| 1363 | + ) |
| 1364 | + |
| 1365 | + def test_create_rule_with_evaluate_dmn_action_empty_config(self): |
| 1366 | + user = SuperUserFactory.create(username="test", password="test") |
| 1367 | + form = FormFactory.create() |
| 1368 | + FormStepFactory.create( |
| 1369 | + form=form, |
| 1370 | + form_definition__configuration={ |
| 1371 | + "components": [ |
| 1372 | + { |
| 1373 | + "type": "number", |
| 1374 | + "key": "age", |
| 1375 | + }, |
| 1376 | + { |
| 1377 | + "type": "number", |
| 1378 | + "key": "income", |
| 1379 | + }, |
| 1380 | + ] |
| 1381 | + }, |
| 1382 | + ) |
| 1383 | + FormVariableFactory.create( |
| 1384 | + form=form, |
| 1385 | + source=FormVariableSources.user_defined, |
| 1386 | + key="canApply", |
| 1387 | + data_type=FormVariableDataTypes.boolean, |
| 1388 | + ) |
| 1389 | + |
| 1390 | + form_logic_data = [ |
| 1391 | + { |
| 1392 | + "form": f"http://testserver{reverse('api:form-detail', kwargs={'uuid_or_slug': form.uuid})}", |
| 1393 | + "order": 0, |
| 1394 | + "is_advanced": True, |
| 1395 | + "json_logic_trigger": True, |
| 1396 | + "actions": [ |
| 1397 | + { |
| 1398 | + "action": { |
| 1399 | + "type": LogicActionTypes.evaluate_dmn, |
| 1400 | + "config": {}, |
| 1401 | + }, |
| 1402 | + }, |
| 1403 | + { |
| 1404 | + "action": { |
| 1405 | + "type": LogicActionTypes.evaluate_dmn, |
| 1406 | + "config": { |
| 1407 | + "plugin_id": "", |
| 1408 | + "decision_definition_id": "", |
| 1409 | + "decision_definition_version": "", |
| 1410 | + "input_mapping": {}, |
| 1411 | + "output_mapping": {}, |
| 1412 | + }, |
| 1413 | + }, |
| 1414 | + }, |
| 1415 | + { |
| 1416 | + "action": { |
| 1417 | + "type": LogicActionTypes.evaluate_dmn, |
| 1418 | + }, |
| 1419 | + }, |
| 1420 | + ], |
| 1421 | + } |
| 1422 | + ] |
| 1423 | + |
| 1424 | + self.client.force_authenticate(user=user) |
| 1425 | + url = reverse("api:form-logic-rules", kwargs={"uuid_or_slug": form.uuid}) |
| 1426 | + response = self.client.put(url, data=form_logic_data) |
| 1427 | + |
| 1428 | + self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code) |
| 1429 | + |
| 1430 | + data = response.json() |
| 1431 | + |
| 1432 | + self.assertEqual(data["invalidParams"][0]["code"], "required") |
| 1433 | + self.assertEqual( |
| 1434 | + data["invalidParams"][0]["name"], "0.actions.0.action.config.pluginId" |
| 1435 | + ) |
| 1436 | + self.assertEqual(data["invalidParams"][1]["code"], "required") |
| 1437 | + self.assertEqual( |
| 1438 | + data["invalidParams"][1]["name"], |
| 1439 | + "0.actions.0.action.config.decisionDefinitionId", |
| 1440 | + ) |
| 1441 | + |
| 1442 | + self.assertEqual(data["invalidParams"][2]["code"], "blank") |
| 1443 | + self.assertEqual( |
| 1444 | + data["invalidParams"][2]["name"], "0.actions.1.action.config.pluginId" |
| 1445 | + ) |
| 1446 | + self.assertEqual(data["invalidParams"][3]["code"], "blank") |
| 1447 | + self.assertEqual( |
| 1448 | + data["invalidParams"][3]["name"], |
| 1449 | + "0.actions.1.action.config.decisionDefinitionId", |
| 1450 | + ) |
| 1451 | + |
| 1452 | + self.assertEqual(data["invalidParams"][4]["code"], "required") |
| 1453 | + self.assertEqual(data["invalidParams"][4]["name"], "0.actions.2.action.config") |
0 commit comments