Skip to content

Commit

Permalink
fix: remove header output from mutations and insertion endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKellerer authored and fengelniederhammer committed Dec 14, 2023
1 parent 05c198e commit ffd6b55
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.genspectrum.lapis.response

import com.fasterxml.jackson.annotation.JsonIgnore
import io.swagger.v3.oas.annotations.media.Schema
import org.genspectrum.lapis.controller.CsvRecord

Expand All @@ -24,6 +25,7 @@ data class NucleotideMutationResponse(
) : CsvRecord {
override fun asArray() = arrayOf(mutation, count.toString(), proportion.toString())

@JsonIgnore
override fun getHeader() = arrayOf("mutation", "count", "proportion")
}

Expand All @@ -45,6 +47,7 @@ data class AminoAcidMutationResponse(
) : CsvRecord {
override fun asArray() = arrayOf(mutation, count.toString(), proportion.toString())

@JsonIgnore
override fun getHeader() = arrayOf("mutation", "count", "proportion")
}

Expand All @@ -64,6 +67,7 @@ data class NucleotideInsertionResponse(
) : CsvRecord {
override fun asArray() = arrayOf(insertion, count.toString())

@JsonIgnore
override fun getHeader() = arrayOf("insertion", "count")
}

Expand All @@ -82,5 +86,6 @@ data class AminoAcidInsertionResponse(
) : CsvRecord {
override fun asArray() = arrayOf(insertion, count.toString())

@JsonIgnore
override fun getHeader() = arrayOf("insertion", "count")
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.genspectrum.lapis.controller

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.node.IntNode
import com.fasterxml.jackson.databind.node.TextNode
import com.ninjasquad.springmockk.MockkBean
Expand All @@ -16,6 +17,9 @@ import org.genspectrum.lapis.response.DetailsData
import org.genspectrum.lapis.response.NucleotideInsertionResponse
import org.genspectrum.lapis.response.NucleotideMutationResponse
import org.genspectrum.lapis.silo.DataVersion
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.containsInAnyOrder
import org.hamcrest.Matchers.hasSize
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
Expand Down Expand Up @@ -236,6 +240,23 @@ class LapisControllerTest(
)
}

@ParameterizedTest(name = "GET {0} only returns mutation, proportion and count")
@MethodSource("getMutationEndpoints")
fun `GET mutations only returns mutation, proportion and count`(endpoint: String) {
setupMutationMock(endpoint, null)

val mvcResult = mockMvc.perform(get("$endpoint?country=Switzerland"))
.andExpect(status().isOk)
.andReturn()

val response = ObjectMapper().readValue(mvcResult.response.contentAsString, Map::class.java)
val data = response["data"] as List<*>
val firstDataObject = data[0] as Map<*, *>

assertThat(firstDataObject.keys, hasSize(3))
assertThat(firstDataObject.keys, containsInAnyOrder("mutation", "proportion", "count"))
}

private fun setupMutationMock(
endpoint: String,
minProportion: Double?,
Expand Down Expand Up @@ -294,6 +315,23 @@ class LapisControllerTest(
.andExpect(jsonPath("\$.info.dataVersion").value(1234))
}

@ParameterizedTest(name = "GET {0} only returns mutation, proportion and count")
@MethodSource("getInsertionEndpoints")
fun `GET insertions only returns insertion and count`(endpoint: String) {
setupInsertionMock(endpoint)

val mvcResult = mockMvc.perform(get("$endpoint?country=Switzerland"))
.andExpect(status().isOk)
.andReturn()

val response = ObjectMapper().readValue(mvcResult.response.contentAsString, Map::class.java)
val data = response["data"] as List<*>
val firstDataObject = data[0] as Map<*, *>

assertThat(firstDataObject.keys, hasSize(2))
assertThat(firstDataObject.keys, containsInAnyOrder("insertion", "count"))
}

private fun setupInsertionMock(endpoint: String) {
when (endpoint) {
NUCLEOTIDE_INSERTIONS_ROUTE -> {
Expand Down

0 comments on commit ffd6b55

Please sign in to comment.