Skip to content

Commit

Permalink
test(backend): add unit test for #2001
Browse files Browse the repository at this point in the history
  • Loading branch information
fengelniederhammer committed May 22, 2024
1 parent b2ec2f6 commit f8e5d66
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,7 @@ class SubmissionDatabaseService(

SequenceEntriesTable.update(
where = {
(SequenceEntriesTable.accessionColumn eq editedAccessionVersion.accession) and
(SequenceEntriesTable.versionColumn eq editedAccessionVersion.version)
SequenceEntriesTable.accessionVersionIsIn(listOf(editedAccessionVersion))
},
) {
it[originalDataColumn] = compressionService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.MatcherAssert.assertThat
import org.loculus.backend.api.AccessionVersion
import org.loculus.backend.api.AccessionVersionInterface
import org.loculus.backend.api.AccessionVersionOriginalMetadata
import org.loculus.backend.api.ApproveDataScope
import org.loculus.backend.api.DataUseTerms
import org.loculus.backend.api.GeneticSequence
Expand All @@ -30,6 +31,7 @@ import org.loculus.backend.controller.generateJwtFor
import org.loculus.backend.controller.getAccessionVersions
import org.loculus.backend.controller.groupmanagement.GroupManagementControllerClient
import org.loculus.backend.controller.groupmanagement.andGetGroupId
import org.loculus.backend.controller.jwtForDefaultUser
import org.loculus.backend.controller.submission.SubmitFiles.DefaultFiles
import org.loculus.backend.utils.Accession
import org.springframework.http.MediaType
Expand Down Expand Up @@ -377,6 +379,24 @@ class SubmissionConvenienceClient(
fun getReleasedData(organism: String = DEFAULT_ORGANISM) =
client.getReleasedData(organism).expectNdjsonAndGetContent<ProcessedData<GeneticSequence>>()

fun getOriginalMetadata(
organism: String = DEFAULT_ORGANISM,
jwt: String? = jwtForDefaultUser,
groupIdsFilter: List<Int>? = null,
statusesFilter: List<Status>? = null,
fields: List<String>? = null,
compression: String? = null,
) = client
.getOriginalMetadata(
organism = organism,
jwt = jwt,
groupIdsFilter = groupIdsFilter,
statusesFilter = statusesFilter,
fields = fields,
compression = compression,
)
.expectNdjsonAndGetContent<AccessionVersionOriginalMetadata>()

private inline fun <reified T> deserializeJsonResponse(resultActions: ResultActions): T {
val content =
resultActions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package org.loculus.backend.controller.submission

import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.anEmptyMap
import org.hamcrest.Matchers.containsString
import org.hamcrest.Matchers.`is`
import org.hamcrest.Matchers.not
import org.junit.jupiter.api.Test
import org.loculus.backend.api.Status
import org.loculus.backend.api.UnprocessedData
Expand Down Expand Up @@ -62,6 +66,26 @@ class SubmitEditedSequenceEntryVersionEndpointTest(
.assertStatusIs(Status.RECEIVED)
}

@Test
fun `GIVEN a sequence entry is processed WHEN I submit edited data THEN has changed original data`() {
val firstAccession = convenienceClient.prepareDataTo(Status.AWAITING_APPROVAL)
.map { it.accession }
.first()

val entryBeforeEdit = convenienceClient.getOriginalMetadata()
.find { it.accession == firstAccession && it.version == 1L }!!
assertThat(entryBeforeEdit.originalMetadata, `is`(not(anEmptyMap())))

val editedData = generateUnprocessedData(firstAccession)

client.submitEditedSequenceEntryVersion(editedData)
.andExpect(status().isNoContent)

val entryAfterEdit = convenienceClient.getOriginalMetadata()
.find { it.accession == firstAccession && it.version == 1L }!!
assertThat(entryAfterEdit.originalMetadata, `is`(anEmptyMap()))
}

@Test
fun `WHEN a version does not exist THEN it returns an unprocessable entity error`() {
val accessions = convenienceClient.prepareDataTo(Status.HAS_ERRORS).map { it.accession }
Expand Down

0 comments on commit f8e5d66

Please sign in to comment.