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(backend): deleting/approving all sequences only affects entries of that organism #1603

Conversation

fengelniederhammer
Copy link
Contributor

@fengelniederhammer fengelniederhammer commented Apr 15, 2024

resolves #1594

preview URL:

Summary

Tests that approvedProcessedData and deleteSequenceEntryVersions only target the respective organism exist only when providing an accession filter:

@Test
fun `WHEN I approve sequence entries of different organisms THEN request should be rejected`() {
val defaultOrganismData = convenienceClient.prepareDataTo(AWAITING_APPROVAL, organism = DEFAULT_ORGANISM)
val otherOrganismData = convenienceClient.prepareDataTo(AWAITING_APPROVAL, organism = OTHER_ORGANISM)
client.approveProcessedSequenceEntries(
scope = ALL,
defaultOrganismData.getAccessionVersions() + otherOrganismData.getAccessionVersions(),
organism = OTHER_ORGANISM,
)
.andExpect(status().isUnprocessableEntity)
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(
jsonPath("$.detail")
.value(containsString("accession versions are not of organism otherOrganism")),
)
convenienceClient.getSequenceEntry(
accession = defaultOrganismData.first().accession,
version = 1,
organism = DEFAULT_ORGANISM,
)
.assertStatusIs(AWAITING_APPROVAL)
convenienceClient.getSequenceEntry(
accession = otherOrganismData.first().accession,
version = 1,
organism = OTHER_ORGANISM,
)
.assertStatusIs(AWAITING_APPROVAL)
}

@Test
fun `WHEN deleting sequence entry of wrong organism THEN throws an unprocessableEntity error`() {
val accessionVersion = convenienceClient.submitDefaultFiles(organism = DEFAULT_ORGANISM).submissionIdMappings[0]
client.deleteSequenceEntries(
scope = ALL,
accessionVersionsFilter = listOf(accessionVersion.toAccessionVersion()),
organism = OTHER_ORGANISM,
)
.andExpect(status().isUnprocessableEntity)
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(
jsonPath("\$.detail", containsString("accession versions are not of organism $OTHER_ORGANISM:")),
)
}

I added tests and fixed the behavior when only the All scope is provided.

From several past discussion it was clear that the interface of the AccessionPreconditionValidator didn't really say what it was actually doing. So I refactored it in a way that should make it quite obvious what is validated (both for reading and for writing code):

        accessionPreconditionValidator.validate {
            thatAccessionsExist(accessions)
                .andThatSequenceEntriesAreInStates(listOf(APPROVED_FOR_RELEASE))
        }

Screenshot

PR Checklist

  • [ ] All necessary documentation has been adapted.
  • The implemented feature is covered by an appropriate test.

…itionValidator verifies #1594

Tests that `approvedProcessedData` and `deleteSequenceEntryVersions` only target the respective organism exist.
@chaoran-chen
Copy link
Member

Do the tests really cover the case that I described in #1594? As far as I can see, the tests only cover the case where the user provides a list of accessions and the organism check only happens if a list of accessions is provided. However, if the user wants to approve or delete all sequences of a particular organism (without providing a list of accessions), we don't filter by that organism.

@fengelniederhammer
Copy link
Contributor Author

Ah, good point. I'll check again.

@fengelniederhammer fengelniederhammer changed the title refactor(backend): make it easier to follow what the AccessionPreconditionValidator verifies fix(backend): deleting/approving all sequences only affects entries of that organism Apr 15, 2024
@fengelniederhammer
Copy link
Contributor Author

Good catch, now it should indeed be fixed :)

Copy link
Member

@chaoran-chen chaoran-chen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! And I like the refactoring, it's indeed easier to understand!

@fengelniederhammer fengelniederhammer merged commit 45122cf into main Apr 15, 2024
11 checks passed
@fengelniederhammer fengelniederhammer deleted the 1594-check-whether-organism-filtering-works-properly-for-approve-processed-data-and-delete-sequence-entry-versions branch April 15, 2024 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check whether organism filtering works properly for approve-processed-data and delete-sequence-entry-versions
2 participants