|
| 1 | +package io.getstream.chat.java; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.annotation.JsonAutoDetect; |
| 4 | +import com.fasterxml.jackson.annotation.PropertyAccessor; |
| 5 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 6 | +import io.getstream.chat.java.models.Message; |
| 7 | +import io.getstream.chat.java.models.Message.MessageRequestObject; |
| 8 | +import org.junit.jupiter.api.Assertions; |
| 9 | +import org.junit.jupiter.api.DisplayName; |
| 10 | +import org.junit.jupiter.api.Test; |
| 11 | + |
| 12 | +public class MessageSkipEnrichUrlTest { |
| 13 | + |
| 14 | + // Mirrors the visibility configuration of DefaultClient's mapper. |
| 15 | + private static final ObjectMapper MAPPER = |
| 16 | + new ObjectMapper() |
| 17 | + .setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE) |
| 18 | + .setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); |
| 19 | + |
| 20 | + private static MessageRequestObject message() { |
| 21 | + return MessageRequestObject.builder().text("https://getstream.io").userId("gandalf").build(); |
| 22 | + } |
| 23 | + |
| 24 | + @DisplayName("Send carries skip_enrich_url next to message") |
| 25 | + @Test |
| 26 | + void whenSendingWithSkipEnrichUrl_thenBodyCarriesIt() throws Exception { |
| 27 | + String body = |
| 28 | + MAPPER.writeValueAsString( |
| 29 | + Message.send("messaging", "general") |
| 30 | + .message(message()) |
| 31 | + .skipEnrichUrl(true) |
| 32 | + .internalBuild()); |
| 33 | + |
| 34 | + Assertions.assertTrue(body.contains("\"skip_enrich_url\":true"), body); |
| 35 | + } |
| 36 | + |
| 37 | + @DisplayName("Update carries skip_enrich_url next to message") |
| 38 | + @Test |
| 39 | + void whenUpdatingWithSkipEnrichUrl_thenBodyCarriesIt() throws Exception { |
| 40 | + String body = |
| 41 | + MAPPER.writeValueAsString( |
| 42 | + Message.update("msg-1").message(message()).skipEnrichUrl(true).internalBuild()); |
| 43 | + |
| 44 | + Assertions.assertTrue(body.contains("\"skip_enrich_url\":true"), body); |
| 45 | + } |
| 46 | + |
| 47 | + @DisplayName("Partial update carries skip_enrich_url") |
| 48 | + @Test |
| 49 | + void whenPartialUpdatingWithSkipEnrichUrl_thenBodyCarriesIt() throws Exception { |
| 50 | + String body = |
| 51 | + MAPPER.writeValueAsString( |
| 52 | + Message.partialUpdate("msg-1") |
| 53 | + .userId("gandalf") |
| 54 | + .setValue("text", "https://getstream.io") |
| 55 | + .skipEnrichUrl(true) |
| 56 | + .internalBuild()); |
| 57 | + |
| 58 | + Assertions.assertTrue(body.contains("\"skip_enrich_url\":true"), body); |
| 59 | + } |
| 60 | +} |
0 commit comments