From 4418caaf9999206b5ae52a49cf4ae512c73e92e5 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Fri, 3 Nov 2023 15:04:09 +0900 Subject: [PATCH] =?UTF-8?q?test:=20Note=E3=81=AE=E3=82=B7=E3=83=AA?= =?UTF-8?q?=E3=82=A2=E3=83=A9=E3=82=A4=E3=82=BA=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/model/NoteSerializeTest.kt | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/NoteSerializeTest.kt 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(json) + + val note = Note( + name = "", + id = "https://misskey.usbharu.dev/notes/9f2i9cm88e", + type = listOf("Note"), + attributedTo = "https://misskey.usbharu.dev/users/97ws8y3rj6", + content = "

@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) + } +}