aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com/juick/server/tests
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-12-28 18:51:46 +0300
committerGravatar Vitaly Takmazov2019-12-28 18:51:46 +0300
commit4c39169bee102b2bfa82b55717a3a4aa75297946 (patch)
treeac3bba2a1cb28e64f88c5334f533bd50259d8e62 /src/test/java/com/juick/server/tests
parentb5e946b42a07527b08b05b3e29d2795b33db9836 (diff)
ActivityPub: fix formatting note with attachments
Diffstat (limited to 'src/test/java/com/juick/server/tests')
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index a8fc4563..5b3d87eb 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -57,6 +57,7 @@ import com.juick.util.MessageUtils;
import com.mitchellbosecke.pebble.PebbleEngine;
import com.mitchellbosecke.pebble.error.PebbleException;
import com.mitchellbosecke.pebble.template.PebbleTemplate;
+import com.overzealous.remark.Remark;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import io.jsonwebtoken.Jwts;
@@ -244,12 +245,16 @@ public class ServerTests {
private Resource hubzillaFollow;
@Value("classpath:announce.json")
private Resource noteWithDocument;
+ @Value("classpath:note_with_attachment.json")
+ private Resource noteWithAttachment;
@Value("classpath:2936611-57.jpg")
private Resource jpegNoJfifTiff;
@Value("classpath:Transparent.gif")
private Resource invisiblePixel;
@Inject
AppleClientSecretGenerator clientSecretGenerator;
+ @Inject
+ private Remark remarkConverter;
@Inject
private KeystoreManager testKeystoreManager;
@@ -2158,6 +2163,17 @@ public class ServerTests {
Message testMessage = MockUtils.mockMessage(mid, freefd, "reply");
String activity = IOUtils.toString(noteWithDocument.getInputStream(), StandardCharsets.UTF_8);
Announce announce = jsonMapper.readValue(activity, Announce.class);
+ String noteString = IOUtils.toString(noteWithAttachment.getInputStream(), StandardCharsets.UTF_8);
+ Create create = jsonMapper.readValue(noteString, Create.class);
+ Map<String, Object> note = (Map<String, Object>) create.getObject();
+ String markdown = remarkConverter.convertFragment((String) note.get("content"));
+ String commandBody = note.get("attachment") == null ? markdown :
+ ((List<Object>) note.get("attachment")).stream().map(attachmentObj -> {
+ Map<String, String> attachment = (Map<String, String>) attachmentObj;
+ String attachmentUrl = attachment.get("url");
+ String attachmentName = attachment.get("name");
+ return PlainTextFormatter.markdownUrl(attachmentUrl, attachmentName);
+ }).reduce(markdown, (current, next) -> String.format("%s\n%s", current, next));
}
@Test