diff --git a/src/test/kotlin/dev/usbharu/hideout/service/ap/APCreateServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/service/ap/APCreateServiceImplTest.kt new file mode 100644 index 00000000..0d3acf72 --- /dev/null +++ b/src/test/kotlin/dev/usbharu/hideout/service/ap/APCreateServiceImplTest.kt @@ -0,0 +1,63 @@ +package dev.usbharu.hideout.service.ap + +import dev.usbharu.hideout.domain.model.ActivityPubStringResponse +import dev.usbharu.hideout.domain.model.ap.Create +import dev.usbharu.hideout.domain.model.ap.Like +import dev.usbharu.hideout.domain.model.ap.Note +import dev.usbharu.hideout.exception.ap.IllegalActivityPubObjectException +import io.ktor.http.* +import kotlinx.coroutines.test.runTest +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.mockito.kotlin.* +import utils.TestTransaction + +class APCreateServiceImplTest { + + @Test + fun `receiveCreate 正常なCreateを処理できる`() = runTest { + val create = Create( + name = "Create", + `object` = Note( + name = "Note", + id = "https://example.com/note", + attributedTo = "https://example.com/actor", + content = "Hello World", + published = "Date: Wed, 21 Oct 2015 07:28:00 GMT" + ), + actor = "https://example.com/actor", + id = "https://example.com/create", + ) + + val apNoteService = mock() + val apCreateServiceImpl = APCreateServiceImpl(apNoteService, TestTransaction) + + val actual = ActivityPubStringResponse(HttpStatusCode.OK, "Created") + + val receiveCreate = apCreateServiceImpl.receiveCreate(create) + verify(apNoteService, times(1)).fetchNote(any(), anyOrNull()) + assertEquals(actual, receiveCreate) + } + + @Test + fun `reveiveCreate CreateのobjectのtypeがNote以外の場合IllegalActivityPubObjectExceptionがthrowされる`() = runTest { + val create = Create( + name = "Create", + `object` = Like( + name = "Like", + id = "https://example.com/note", + actor = "https://example.com/actor", + `object` = "https://example.com/create", + content = "aaa" + ), + actor = "https://example.com/actor", + id = "https://example.com/create", + ) + + val apCreateServiceImpl = APCreateServiceImpl(mock(), TestTransaction) + assertThrows { + apCreateServiceImpl.receiveCreate(create) + } + } +}