Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix accidental submission counter reset #4983

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading