aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2022-10-04 21:45:26 +0300
committerGravatar Vitaly Takmazov2022-10-04 21:45:26 +0300
commit21927063ea989551613ae35ab4b71c9e880db0a1 (patch)
tree07c32ae12be0e929ee9570e4eaff13614e376c5b
parent8ec8241b63ae6b59e3d4a17bd7feb11723820eac (diff)
Always include empty pms list in `groups_pms` API response
-rw-r--r--src/main/java/com/juick/model/PrivateChats.java2
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java14
2 files changed, 15 insertions, 1 deletions
diff --git a/src/main/java/com/juick/model/PrivateChats.java b/src/main/java/com/juick/model/PrivateChats.java
index 7a20ddbc..c480d00a 100644
--- a/src/main/java/com/juick/model/PrivateChats.java
+++ b/src/main/java/com/juick/model/PrivateChats.java
@@ -17,6 +17,7 @@
package com.juick.model;
+import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Collections;
@@ -34,6 +35,7 @@ public class PrivateChats {
}
@JsonProperty("pms")
+ @JsonInclude(JsonInclude.Include.ALWAYS)
public List<Chat> getUsers() {
return users;
}
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index 0971f6b1..87617cea 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -32,6 +32,7 @@ import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.startsWith;
+import static org.hamcrest.collection.IsEmptyCollection.empty;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -2511,7 +2512,8 @@ public class ServerTests {
@Test
public void invalidMediaTypeTest() throws Exception {
- mockMvc.perform(get("/api/messages").header("Accept", "application/xml")).andExpect(status().isBadRequest())
+ mockMvc.perform(get("/api/messages")
+ .header("Accept", "application/xml")).andExpect(status().isBadRequest())
.andExpect(content().string("Invalid media type"));
}
@@ -2521,4 +2523,14 @@ public class ServerTests {
String contextString = jsonMapper.writeValueAsString(context);
assertThat(contextString, is("{\"id\":\"http://juick.com/u/ermine\"}"));
}
+
+ @Test
+ public void emptyListForEmptyChatsList() throws Exception {
+ jdbcTemplate.execute("DELETE FROM pm");
+ mockMvc.perform(
+ get("/api/groups_pms").with(httpBasic(ugnichName, ugnichPassword)))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.pms", empty()));
+
+ }
}