Skip to content

Commit

Permalink
Merge pull request #5545 from seadowg/audit-log-constraint
Browse files Browse the repository at this point in the history
Don't flush audit log when constraints fail
  • Loading branch information
grzesiek2010 authored Apr 19, 2023
2 parents 8ecbb96 + c037f7d commit 023c3e9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0"?>
<h:html xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:h="http://www.w3.org/1999/xhtml"
xmlns:jr="http://openrosa.org/javarosa" xmlns:odk="http://www.opendatakit.org/xforms"
xmlns:orx="http://openrosa.org/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.w3.org/2002/xforms">
<h:head>
<h:title>One Question Audit Constraint</h:title>
<model>
<instance>
<data id="one_question_audit" orx:version="1">
<age />
<meta>
<audit />
</meta>
</data>
</instance>
<bind constraint=". &lt; 120" nodeset="age" type="int" jr:constraintMsg="Too old!" />
<bind nodeset="/data/meta/audit" type="binary" odk:track-changes="true" />
</model>
</h:head>
<h:body>
<input ref="/data/age">
<label>What is your age?</label>
</input>
</h:body>
</h:html>
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ public void moveForward(HashMap<FormIndex, IAnswerData> answers, Boolean evaluat
}, updateSuccess -> {
isLoading.setValue(false);

formController.getAuditEventLogger().flush();

if (updateSuccess) {
try {
formController.stepToNextScreenEvent();
Expand All @@ -211,8 +209,6 @@ public void moveBackward(HashMap<FormIndex, IAnswerData> answers) {
}, updateSuccess -> {
isLoading.setValue(false);

formController.getAuditEventLogger().flush();

if (updateSuccess) {
try {
formController.stepToPreviousScreenEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ public void moveForward_savesAnswersToFormController_andThenStepsToNextEvent_and
scheduler.runBackground();
InOrder verifier = inOrder(formController, auditEventLogger);
verifier.verify(formController).saveAllScreenAnswers(answers, false);
verifier.verify(auditEventLogger).flush();
verifier.verify(formController).stepToNextScreenEvent();
verifier.verify(auditEventLogger).flush();
}
Expand Down Expand Up @@ -238,6 +237,20 @@ public void moveForward_whenThereIsAFailedConstraint_setsFailedConstraint() thro
assertThat(getOrAwaitValue(viewModel.getFailedConstraint()), equalTo(failedConstraint));
}

/**
* We don't want to flush the log before answers are actually committed.
*/
@Test
public void moveForward_whenThereIsAFailedConstraint_doesNotFlushAuditLog() throws Exception {
FailedConstraint failedConstraint = new FailedConstraint(startingIndex, 0);
when(formController.saveAllScreenAnswers(any(), anyBoolean())).thenReturn(failedConstraint);

viewModel.moveForward(new HashMap<>());
scheduler.runBackground();

verify(auditEventLogger, never()).flush();
}

@Test
public void moveForward_whenThereIsAFailedConstraint_doesNotStepToNextEvent() throws Exception {
FailedConstraint failedConstraint = new FailedConstraint(startingIndex, 0);
Expand Down Expand Up @@ -297,7 +310,6 @@ public void moveBackward_savesAnswersToFormController_andThenStepsToPreviousEven
scheduler.runBackground();
InOrder verifier = inOrder(formController, auditEventLogger);
verifier.verify(formController).saveAllScreenAnswers(answers, false);
verifier.verify(auditEventLogger).flush();
verifier.verify(formController).stepToPreviousScreenEvent();
verifier.verify(auditEventLogger).flush();
}
Expand Down

0 comments on commit 023c3e9

Please sign in to comment.