From 4c39169bee102b2bfa82b55717a3a4aa75297946 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 28 Dec 2019 18:51:46 +0300 Subject: ActivityPub: fix formatting note with attachments --- src/test/java/com/juick/server/tests/ServerTests.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/test/java') 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 note = (Map) create.getObject(); + String markdown = remarkConverter.convertFragment((String) note.get("content")); + String commandBody = note.get("attachment") == null ? markdown : + ((List) note.get("attachment")).stream().map(attachmentObj -> { + Map attachment = (Map) 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 -- cgit v1.2.3