-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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(Surveys): Guard for nil iteration_count when updating survey iterations #23917
Merged
+68
−4
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a6a6036
guard for nil iteration_count when updating survey iterations
Phanatic 775e309
Merge branch 'master' into fix-none-comparision
Phanatic cb0aaa7
Merge branch 'master' into fix-none-comparision
Phanatic 860d552
fix test
Phanatic bad0bb3
Merge branch 'master' into fix-none-comparision
Phanatic 14d2f5a
Actually reset current_iteration after recurrence is disabled
Phanatic 8b049c5
Merge branch 'master' into fix-none-comparision
dmarticus c5a24e5
more tests
Phanatic 0b4a287
Merge branch 'master' into fix-none-comparision
dmarticus e7a0c87
fix statement unreachable error
Phanatic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -958,7 +958,6 @@ def test_can_list_surveys(self): | |
response_data = list.json() | ||
assert list.status_code == status.HTTP_200_OK, response_data | ||
survey = Survey.objects.get(team_id=self.team.id) | ||
|
||
assert response_data == { | ||
"count": 1, | ||
"next": None, | ||
|
@@ -1019,7 +1018,7 @@ def test_can_list_surveys(self): | |
"responses_limit": None, | ||
"iteration_count": None, | ||
"iteration_frequency_days": None, | ||
"iteration_start_dates": None, | ||
"iteration_start_dates": [], | ||
"current_iteration": None, | ||
"current_iteration_start_date": None, | ||
} | ||
|
@@ -2233,6 +2232,27 @@ def _create_recurring_survey(self) -> Survey: | |
survey = Survey.objects.get(id=response_data["id"]) | ||
return survey | ||
|
||
def _create_non_recurring_survey(self) -> Survey: | ||
random_id = generate("1234567890abcdef", 10) | ||
response = self.client.post( | ||
f"/api/projects/{self.team.id}/surveys/", | ||
data={ | ||
"name": f"Recurring NPS Survey {random_id}", | ||
"description": "Get feedback on the new notebooks feature", | ||
"type": "popover", | ||
"questions": [ | ||
{ | ||
"type": "open", | ||
"question": "What's a survey?", | ||
} | ||
], | ||
}, | ||
) | ||
|
||
response_data = response.json() | ||
survey = Survey.objects.get(id=response_data["id"]) | ||
return survey | ||
|
||
def test_can_create_recurring_survey(self): | ||
survey = self._create_recurring_survey() | ||
response = self.client.patch( | ||
|
@@ -2346,6 +2366,41 @@ def test_cannot_reduce_iterations_lt_current_iteration(self): | |
assert response.status_code == status.HTTP_400_BAD_REQUEST | ||
assert response.json()["detail"] == "Cannot change survey recurrence to 1, should be at least 2" | ||
|
||
def test_can_handle_non_nil_current_iteration(self): | ||
survey = self._create_non_recurring_survey() | ||
survey.current_iteration = 2 | ||
survey.save() | ||
response = self.client.patch( | ||
f"/api/projects/{self.team.id}/surveys/{survey.id}/", | ||
data={ | ||
"start_date": datetime.now() - timedelta(days=1), | ||
}, | ||
) | ||
assert response.status_code == status.HTTP_200_OK | ||
|
||
def test_guards_for_nil_iteration_count(self): | ||
survey = self._create_recurring_survey() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this creates a survey with an iteration count, though, right? Shouldn't our test handle the case where we don't have an iteration count and we confirm that the API doesn't fail, since that was the case that failed in production? |
||
survey.current_iteration = 2 | ||
survey.save() | ||
response = self.client.patch( | ||
f"/api/projects/{self.team.id}/surveys/{survey.id}/", | ||
data={ | ||
"start_date": datetime.now() - timedelta(days=1), | ||
}, | ||
) | ||
assert response.status_code == status.HTTP_200_OK | ||
survey.refresh_from_db() | ||
self.assertIsNone(survey.current_iteration) | ||
response = self.client.patch( | ||
f"/api/projects/{self.team.id}/surveys/{survey.id}/", | ||
data={ | ||
"start_date": datetime.now() - timedelta(days=1), | ||
"iteration_count": 3, | ||
"iteration_frequency_days": 30, | ||
}, | ||
) | ||
assert response.status_code == status.HTTP_200_OK | ||
|
||
def test_can_turn_off_recurring_schedule(self): | ||
survey = self._create_recurring_survey() | ||
response = self.client.patch( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, so this was the fix I was going to go with, but the reason I didn't just fix this myself is because this doesn't tell me why these illegal states are possible? Like, if we have a situation where we have a
current_iteration
but noiteration_count
, isn't that something we should make impossible or force-correct? can you tell me more about how this state could be reached?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an invalid state, where the survey previously had recurrence set on it and went to current_iteration of 2.
Then recurrence was disabled and customer tried to set it to be recurring again. Let me write a test for the full scenario.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 14d2f5a#diff-c2c811931c76d29d59ee8c932d3ef20d484ecffe1fa1ca049f6abae7edf437a2R179-R184