Skip to content

Commit

Permalink
test(backend): Test that updated group info ends up in released data (#…
Browse files Browse the repository at this point in the history
…2943)

* Failing test

* Add init that was missing
# Conflicts:
#	backend/src/test/kotlin/org/loculus/backend/controller/submission/GetReleasedDataEndpointTest.kt
  • Loading branch information
fhennig authored and corneliusroemer committed Oct 16, 2024
1 parent 8dc010b commit 8f752dc
Showing 1 changed file with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.hamcrest.Matchers.not
import org.hamcrest.Matchers.notNullValue
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.keycloak.representations.idm.UserRepresentation
import org.loculus.backend.api.AccessionVersionInterface
import org.loculus.backend.api.DataUseTerms
import org.loculus.backend.api.DataUseTermsChangeRequest
Expand All @@ -39,16 +40,22 @@ import org.loculus.backend.config.BackendConfig
import org.loculus.backend.config.BackendSpringProperty
import org.loculus.backend.config.DataUseTermsUrls
import org.loculus.backend.config.readBackendConfig
import org.loculus.backend.controller.DEFAULT_GROUP
import org.loculus.backend.controller.DEFAULT_GROUP_CHANGED
import org.loculus.backend.controller.DEFAULT_GROUP_NAME
import org.loculus.backend.controller.DEFAULT_GROUP_NAME_CHANGED
import org.loculus.backend.controller.DEFAULT_USER_NAME
import org.loculus.backend.controller.EndpointTest
import org.loculus.backend.controller.datauseterms.DataUseTermsControllerClient
import org.loculus.backend.controller.dateMonthsFromNow
import org.loculus.backend.controller.expectNdjsonAndGetContent
import org.loculus.backend.controller.groupmanagement.GroupManagementControllerClient
import org.loculus.backend.controller.groupmanagement.andGetGroupId
import org.loculus.backend.controller.jacksonObjectMapper
import org.loculus.backend.controller.jwtForDefaultUser
import org.loculus.backend.controller.submission.GetReleasedDataEndpointWithDataUseTermsUrlTest.ConfigWithModifiedDataUseTermsUrlSpringConfig
import org.loculus.backend.controller.submission.SubmitFiles.DefaultFiles.NUMBER_OF_SEQUENCES
import org.loculus.backend.service.KeycloakAdapter
import org.loculus.backend.utils.Accession
import org.loculus.backend.utils.DateProvider
import org.loculus.backend.utils.Version
Expand Down Expand Up @@ -77,12 +84,21 @@ private val ADDED_FIELDS_WITH_UNKNOWN_VALUES_FOR_RELEASE = listOf(

@EndpointTest
class GetReleasedDataEndpointTest(
@Autowired val convenienceClient: SubmissionConvenienceClient,
@Autowired val submissionControllerClient: SubmissionControllerClient,
@Autowired private val convenienceClient: SubmissionConvenienceClient,
@Autowired private val submissionControllerClient: SubmissionControllerClient,
@Autowired private val groupClient: GroupManagementControllerClient,
) {
private val currentYear = Clock.System.now().toLocalDateTime(DateProvider.timeZone).year
private val currentDate = Clock.System.now().toLocalDateTime(DateProvider.timeZone).date.toString()

@MockkBean
lateinit var keycloakAdapter: KeycloakAdapter

@BeforeEach
fun setup() {
every { keycloakAdapter.getUsersWithName(any()) } returns listOf(UserRepresentation())
}

@Test
fun `GIVEN no sequence entries in database THEN returns empty response & etag in header`() {
val response = submissionControllerClient.getReleasedData()
Expand All @@ -96,9 +112,17 @@ class GetReleasedDataEndpointTest(

@Test
fun `GIVEN released data exists THEN returns it with additional metadata fields`() {
convenienceClient.prepareDefaultSequenceEntriesToApprovedForRelease()
// TODO: GIVEN a group update is performed, the updated group info ends up in released data
// Here: Call group info update
val groupId = groupClient.createNewGroup(group = DEFAULT_GROUP, jwt = jwtForDefaultUser)
.andExpect(status().isOk)
.andGetGroupId()

convenienceClient.prepareDefaultSequenceEntriesToApprovedForRelease(groupId = groupId)

groupClient.updateGroup(
groupId = groupId,
group = DEFAULT_GROUP_CHANGED,
jwt = jwtForDefaultUser,
)

val response = submissionControllerClient.getReleasedData()

Expand All @@ -119,7 +143,7 @@ class GetReleasedDataEndpointTest(
"accessionVersion" to TextNode("$id.$version"),
"isRevocation" to BooleanNode.FALSE,
"submitter" to TextNode(DEFAULT_USER_NAME),
"groupName" to TextNode(DEFAULT_GROUP_NAME), // Change this to updated group name
"groupName" to TextNode(DEFAULT_GROUP_NAME_CHANGED),
"versionStatus" to TextNode("LATEST_VERSION"),
"dataUseTerms" to TextNode("OPEN"),
"releasedDate" to TextNode(currentDate),
Expand All @@ -139,7 +163,7 @@ class GetReleasedDataEndpointTest(
"submittedAtTimestamp" -> expectIsTimestampWithCurrentYear(value)
"releasedAtTimestamp" -> expectIsTimestampWithCurrentYear(value)
"submissionId" -> assertThat(value.textValue(), matchesPattern("^custom\\d$"))
"groupId" -> assertThat(value.intValue(), greaterThan(0))
"groupId" -> assertThat(value.intValue(), `is`(groupId))
else -> assertThat(value, `is`(expectedMetadata[key]))
}
}
Expand Down

0 comments on commit 8f752dc

Please sign in to comment.