Skip to content

Commit

Permalink
Merge pull request #4983 from open-formulieren/issue/4969-avoid-reset…
Browse files Browse the repository at this point in the history
…ting-submission-counter

Fix accidental submission counter reset
  • Loading branch information
sergei-maertens authored Jan 2, 2025
2 parents 31220c8 + cbc7608 commit 25fba12
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
47 changes: 47 additions & 0 deletions src/openforms/forms/tests/e2e_tests/test_form_designer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from openforms.utils.tests.cache import clear_caches
from openforms.variables.constants import FormVariableDataTypes, FormVariableSources

from ...models import Form
from ..factories import (
FormDefinitionFactory,
FormFactory,
Expand Down Expand Up @@ -1300,6 +1301,52 @@ def setUpTestData():
await page.keyboard.press("ArrowDown")
await expect(page.get_by_text("Field 2 (field2)")).to_be_visible()

@tag("gh-4969")
async def test_saving_form_does_not_reset_submission_counter(self):
@sync_to_async
def setUpTestData():
# set up a form
form = FormFactory.create(generate_minimal_setup=True, submission_counter=0)
return form

@sync_to_async
def update_submission_counter(form: Form):
form.submission_counter = 10
form.save(update_fields=["submission_counter"])

await create_superuser()
form = await setUpTestData()
admin_url = str(
furl(self.live_server_url)
/ reverse("admin:forms_form_change", args=(form.pk,))
)

async with browser_page() as page:
await self._admin_login(page)
await page.goto(str(admin_url))
await expect(
page.get_by_role("tab", name="Steps and fields")
).to_be_visible()

# now, after loading the form, modify the submission counter, simulating some
# submissions happened while the form was opened in some admin screen.
await update_submission_counter(form)

# Save form
await page.get_by_role("button", name="Save", exact=True).click()
changelist_url = str(
furl(self.live_server_url) / reverse("admin:forms_form_changelist")
)
await expect(page).to_have_url(changelist_url)

@sync_to_async
def assert_state(form: Form):
form.refresh_from_db()

self.assertEqual(form.submission_counter, 10)

await assert_state(form)


class FormDesignerTooltipTests(E2ETestCase):
async def test_tooltip_fields_are_present(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ const saveForm = async (state, csrftoken) => {
form: {uuid},
} = state;
const cleanedState = produce(state, draft => {
delete draft.form.registrationBackend; // deprecated
delete draft.form.registrationBackendOptions; // deprecated
// ensure we don't overwrite the submission counter with a stale state
delete draft.form.submissionCounter;
normalizeLimit(draft, 'successfulSubmissionsRemovalLimit');
normalizeLimit(draft, 'incompleteSubmissionsRemovalLimit');
normalizeLimit(draft, 'erroredSubmissionsRemovalLimit');
Expand Down

0 comments on commit 25fba12

Please sign in to comment.