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

Pivotal ID # 181381956: Filter Active Requests For Existing Submissions #516

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
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ internal class SubmissionMongoQueryService(
val offset = max(0, filter.offset - requestsCount)
val limit = filter.limit - requests.size
val submissionFilter = filter.copy(limit = limit, offset = offset)
return requests.map { it.asBasicSubmission() } + getSubmissions(owner, submissionFilter)
val drafts = requests.map { it.asBasicSubmission() }
val draftsKeys = drafts.associateBy { it.accNo }
val submissions = getSubmissions(owner, submissionFilter).filter { draftsKeys.containsKey(it.accNo).not() }

return drafts + submissions
}

private fun getSubmissions(owner: String, filter: SubmissionFilter): List<BasicSubmission> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,25 +181,24 @@ internal class SubmissionMongoQueryServiceTest(

@Test
fun `filtered by accNo`() {
val request1 =
saveAsRequest(extSubmission.copy(accNo = "accNo1", title = "title1", section = section), REQUESTED)
val sub1 = submissionRepo.save(docSubmission.copy(accNo = "accNo1", status = PROCESSED))
val subRequest = extSubmission.copy(accNo = "accNo1", version = 2, title = "title1", section = section)
val savedRequest = saveAsRequest(subRequest, REQUESTED)
submissionRepo.save(docSubmission.copy(accNo = "accNo1", status = PROCESSED))

var result = testInstance.getSubmissionsByUser(
SUBMISSION_OWNER,
SubmissionFilter(accNo = "accNo1", limit = 1)
)

assertThat(result).hasSize(1)
assertThat(result.first()).isEqualTo(request1.asBasicSubmission())
assertThat(result.first()).isEqualTo(savedRequest.asBasicSubmission())

result = testInstance.getSubmissionsByUser(
SUBMISSION_OWNER,
SubmissionFilter(accNo = "accNo1", limit = 2)
)
assertThat(result).hasSize(2)
assertThat(result.first()).isEqualTo(request1.asBasicSubmission())
assertThat(result.second()).isEqualTo(sub1.asBasicSubmission())
assertThat(result).hasSize(1)
assertThat(result.first()).isEqualTo(savedRequest.asBasicSubmission())
}

@Test
Expand Down Expand Up @@ -369,22 +368,14 @@ internal class SubmissionMongoQueryServiceTest(
)
)

assertThat(result).hasSize(2)
assertThat(result).hasSize(1)
val request = result.first()
assertThat(request.accNo).isEqualTo("accNo1")
assertThat(request.version).isEqualTo(1)
assertThat(request.title).isEqualTo("title")
assertThat(request.releaseTime).isEqualTo(OffsetDateTime.of(2020, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC))
assertThat(request.released).isEqualTo(false)
assertThat(request.status).isEqualTo(ProcessingStatus.REQUESTED)

val submission = result.second()
assertThat(submission.accNo).isEqualTo("accNo1")
assertThat(submission.version).isEqualTo(1)
assertThat(submission.title).isEqualTo("title")
assertThat(submission.releaseTime).isEqualTo(OffsetDateTime.of(2020, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC))
assertThat(submission.released).isEqualTo(false)
assertThat(submission.status).isEqualTo(ProcessingStatus.PROCESSED)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal class SubmissionListApiTest(private val tempFolder: TemporaryFolder) :
}

@Test
@Disabled("If submission is processed fast enough test wil fail. Needs re desing.")
@Disabled("If submission is processed fast enough test wil fail. Needs re design.")
fun `get submission when processing`() {
val newVersion = getSimpleSubmission(18)
webClient.submitAsync(newVersion, TSV)
Expand Down