Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -515,11 +515,13 @@ fun ExpressionEntity.toModelObject(): Expression =
optionIds = optionIds?.split(',')?.toSet() ?: setOf(),
)

@Throws(LocalDataConsistencyException::class)
fun DraftSubmissionEntity.toModelObject(survey: Survey): DraftSubmission {
fun DraftSubmissionEntity.toModelObject(survey: Survey): DraftSubmission? {
val job =
survey.getJob(jobId)
?: throw LocalDataConsistencyException("Unknown jobId in submission mutation $id")
?: run {
Timber.w("Draft submission $id references jobId $jobId that no longer exists, discarding")
return null
}

return DraftSubmission(
id = id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,26 @@ class DataCollectionFragmentTest : BaseHiltTest() {
.assertInputTextDisplayed(TASK_CONDITIONAL_RESPONSE)
}

@Test
fun `Does not load draft if it references missing job`() =
runWithTestDispatcher {
setupFragment()

runner().inputText(TASK_1_RESPONSE).clickNextButton()

// Verify draft was saved
val draftId = submissionRepository.getDraftSubmissionsId()
assertThat(draftId).isNotEmpty()
assertThat(submissionRepository.countDraftSubmissions()).isEqualTo(1)

// Simulate deleting the job from the submission
val surveyWithMissingJob = SURVEY.copy(jobMap = emptyMap())

// Attempt to get draft with the survey that's missing the job
val result = submissionRepository.getDraftSubmission(draftId, surveyWithMissingJob)
assertThat(result).isNull()
}

@Test
fun `Clicking done on final task saves the submission`() = runWithTestDispatcher {
setupFragment()
Expand Down
Loading