Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

fix: no nullable result from lab allowed #64

Merged
merged 3 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
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 @@ -65,7 +65,7 @@ public ResponseEntity<TestResultResponse> result(
log.info("Received test result request from app.");
TestResult result = testResultService.getOrCreate(request.getId());
return ResponseEntity.ok(new TestResultResponse()
.setTestResult(result.getResult() == null ? 0 : result.getResult()));
.setTestResult(result.getResult()));
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/app/coronawarn/testresult/model/TestResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand Down Expand Up @@ -56,6 +57,7 @@ public class TestResult {
*/
@Min(1)
@Max(3)
@NotNull
private Integer result;

public TestResult setId(String id) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/db/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ databaseChangeLog:
- include:
file: changelog/v001-update-test-result-result-nullable.yml
relativeToChangelogFile: true
- include:
file: changelog/v002-revert-test-result-result-nullable.yml
relativeToChangelogFile: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
databaseChangeLog:
- changeSet:
id: revert-test-result-result-nullable
author: jhagestedt
changes:
- addNotNullConstraint:
tableName: test_result
columnName: result
columnDataType: integer
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void before() {
}

@Test
public void insertInvalidShouldReturnBadRequest() throws Exception {
public void insertInvalidIdShouldReturnBadRequest() throws Exception {
// data
String id = "";
Integer result = 0;
Expand All @@ -77,25 +77,35 @@ public void insertInvalidShouldReturnBadRequest() throws Exception {
}

@Test
public void insertValidShouldReturnNoContent() throws Exception {
public void insertInvalidResultShouldReturnBadRequest() throws Exception {
// data
String id = "a".repeat(64);
Integer result = 1;
// create
List<TestResult> valid = Collections.singletonList(
new TestResult().setId(id).setResult(result)
List<TestResult> invalid = Collections.singletonList(
new TestResult().setId(id)
);
mockMvc.perform(MockMvcRequestBuilders
.post("/api/v1/lab/results")
.accept(MediaType.APPLICATION_JSON_VALUE)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(objectMapper.writeValueAsString(valid)))
.content(objectMapper.writeValueAsString(invalid)))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isNoContent());
.andExpect(MockMvcResultMatchers.status().isBadRequest());
// create
invalid = Collections.singletonList(
new TestResult().setId(id).setResult(4)
);
mockMvc.perform(MockMvcRequestBuilders
.post("/api/v1/lab/results")
.accept(MediaType.APPLICATION_JSON_VALUE)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(objectMapper.writeValueAsString(invalid)))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isBadRequest());
}

@Test
public void insertValidAndGetShouldReturnOk() throws Exception {
public void insertValidShouldReturnNoContent() throws Exception {
// data
String id = "b".repeat(64);
Integer result = 1;
Expand All @@ -110,25 +120,16 @@ public void insertValidAndGetShouldReturnOk() throws Exception {
.content(objectMapper.writeValueAsString(valid)))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isNoContent());
// get
TestResultRequest request = new TestResultRequest()
.setId(id);
mockMvc.perform(MockMvcRequestBuilders
.post("/api/v1/app/result")
.accept(MediaType.APPLICATION_JSON_VALUE)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(objectMapper.writeValueAsString(request)))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk());
}

@Test
public void insertValidPendingAndGetShouldReturnOk() throws Exception {
public void insertValidAndGetShouldReturnOk() throws Exception {
// data
String id = "b".repeat(64);
String id = "c".repeat(64);
Integer result = 1;
// create
List<TestResult> valid = Collections.singletonList(
new TestResult().setId(id)
new TestResult().setId(id).setResult(result)
);
mockMvc.perform(MockMvcRequestBuilders
.post("/api/v1/lab/results")
Expand All @@ -152,7 +153,7 @@ public void insertValidPendingAndGetShouldReturnOk() throws Exception {
@Test
public void notExistingTestResultShouldReturnOk() throws Exception {
// data
String id = "b".repeat(64);
String id = "d".repeat(64);
Integer result = 1;
// create
List<TestResult> valid = Collections.singletonList(
Expand Down