Skip to content
Closed
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 @@ -39,6 +39,48 @@ class MetricsControllerTest {
@MockBean
private MetricsService metricsService;

@Test
void queryShouldReturnBadRequestWhenMetricIsBlank() throws Exception {
mockMvc.perform(post("/api/metrics/query")
.contentType(MediaType.APPLICATION_JSON)
.content("""
{"metric":" ","start":1784107658,"end":1784108558,"step":"30s"}
"""))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.code").value(400))
.andExpect(jsonPath("$.message").value("Metric query is required"));

verifyNoInteractions(metricsService);
}

@Test
void queryShouldReturnBadRequestWhenStartIsNotPositive() throws Exception {
mockMvc.perform(post("/api/metrics/query")
.contentType(MediaType.APPLICATION_JSON)
.content("""
{"metric":"up","start":0,"end":1784108558,"step":"30s"}
"""))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.code").value(400))
.andExpect(jsonPath("$.message").value("Metric query start must be positive"));

verifyNoInteractions(metricsService);
}

@Test
void queryShouldReturnBadRequestWhenStepIsBlank() throws Exception {
mockMvc.perform(post("/api/metrics/query")
.contentType(MediaType.APPLICATION_JSON)
.content("""
{"metric":"up","start":1784107658,"end":1784108558,"step":""}
"""))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.code").value(400))
.andExpect(jsonPath("$.message").value("Metric query step is required"));

verifyNoInteractions(metricsService);
}

@Test
void queryShouldReturnBadRequestWhenFieldTypeIsInvalid() throws Exception {
mockMvc.perform(post("/api/metrics/query")
Expand Down
Loading