diff --git a/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/NoteSerializeTest.kt b/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/NoteSerializeTest.kt new file mode 100644 index 00000000..1b05eef1 --- /dev/null +++ b/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/NoteSerializeTest.kt @@ -0,0 +1,83 @@ +package dev.usbharu.hideout.activitypub.domain.model + +import com.fasterxml.jackson.module.kotlin.readValue +import dev.usbharu.hideout.activitypub.service.objects.note.APNoteServiceImpl.Companion.public +import dev.usbharu.hideout.application.config.ActivityPubConfig +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test + +class NoteSerializeTest { + @Test + fun Noteのシリアライズができる() { + val note = Note( + name = "Note", + id = "https://example.com", + attributedTo = "https://example.com/actor", + content = "Hello", + published = "2023-05-20T10:28:17.308Z", + ) + + val objectMapper = ActivityPubConfig().objectMapper() + + val writeValueAsString = objectMapper.writeValueAsString(note) + + assertEquals( + "{\"type\":\"Note\",\"name\":\"Note\",\"id\":\"https://example.com\",\"attributedTo\":\"https://example.com/actor\",\"content\":\"Hello\",\"published\":\"2023-05-20T10:28:17.308Z\",\"sensitive\":false}", + writeValueAsString + ) + } + + @Test + fun Noteのデシリアライズができる() { + //language=JSON + val json = """{ + "id": "https://misskey.usbharu.dev/notes/9f2i9cm88e", + "type": "Note", + "attributedTo": "https://misskey.usbharu.dev/users/97ws8y3rj6", + "content": "
@trapezial@calckey.jp いやそういうことじゃなくて、連合先と自インスタンスで状態が狂うことが多いのでどっちに合わせるべきかと…
", + "_misskey_content": "@trapezial@calckey.jp いやそういうことじゃなくて、連合先と自インスタンスで状態が狂うことが多いのでどっちに合わせるべきかと…", + "source": { + "content": "@trapezial@calckey.jp いやそういうことじゃなくて、連合先と自インスタンスで状態が狂うことが多いのでどっちに合わせるべきかと…", + "mediaType": "text/x.misskeymarkdown" + }, + "published": "2023-05-22T14:26:53.600Z", + "to": [ + "https://misskey.usbharu.dev/users/97ws8y3rj6/followers" + ], + "cc": [ + "https://www.w3.org/ns/activitystreams#Public", + "https://calckey.jp/users/9bu1xzwjyb" + ], + "inReplyTo": "https://calckey.jp/notes/9f2i7ymf1d", + "attachment": [], + "sensitive": false, + "tag": [ + { + "type": "Mention", + "href": "https://calckey.jp/users/9bu1xzwjyb", + "name": "@trapezial@calckey.jp" + } + ] + }""" + + val objectMapper = ActivityPubConfig().objectMapper() + + val readValue = objectMapper.readValue@trapezial@calckey.jp いやそういうことじゃなくて、連合先と自インスタンスで状態が狂うことが多いのでどっちに合わせるべきかと…
", + published = "2023-05-22T14:26:53.600Z", + to = listOf("https://misskey.usbharu.dev/users/97ws8y3rj6/followers"), + cc = listOf(public, "https://calckey.jp/users/9bu1xzwjyb"), + sensitive = false, + inReplyTo = "https://calckey.jp/notes/9f2i7ymf1d", + attachment = emptyList() + ) + note.name = null + assertEquals(note, readValue) + } +}