From 94f790d0398ad8740368ec44406e9861e2b3c0fc Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sun, 11 Aug 2024 16:07:10 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=E6=A8=A9=E9=99=90=E3=83=81=E3=82=A7?= =?UTF-8?q?=E3=83=83=E3=82=AF=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hideout-mastodon/build.gradle.kts | 27 ++++++++++++++ .../StatusQueryServiceImplTest.kt | 33 +++++++++++++++++ .../src/test/resources/application.yml | 12 +++++++ .../src/test/resources/sql/actors.sql | 35 +++++++++++++++++++ .../src/test/resources/sql/posts.sql | 15 ++++++++ .../src/test/resources/sql/relationships.sql | 5 +++ 6 files changed, 127 insertions(+) create mode 100644 hideout-mastodon/src/test/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/StatusQueryServiceImplTest.kt create mode 100644 hideout-mastodon/src/test/resources/application.yml create mode 100644 hideout-mastodon/src/test/resources/sql/actors.sql create mode 100644 hideout-mastodon/src/test/resources/sql/posts.sql create mode 100644 hideout-mastodon/src/test/resources/sql/relationships.sql diff --git a/hideout-mastodon/build.gradle.kts b/hideout-mastodon/build.gradle.kts index 597af703..5eafc93e 100644 --- a/hideout-mastodon/build.gradle.kts +++ b/hideout-mastodon/build.gradle.kts @@ -17,6 +17,27 @@ version = "1.0-SNAPSHOT" repositories { mavenCentral() + maven { + url = uri("https://git.usbharu.dev/api/packages/usbharu/maven") + } + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/usbharu/http-signature") + credentials { + + username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME") + password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN") + } + } + maven { + name = "GitHubPackages2" + url = uri("https://maven.pkg.github.com/multim-dev/emoji-kt") + credentials { + + username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME") + password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN") + } + } } configurations { @@ -42,8 +63,14 @@ dependencies { implementation(libs.bundles.exposed) implementation(libs.bundles.openapi) implementation(libs.bundles.coroutines) + + testImplementation("org.springframework.boot:spring-boot-starter-test") + testImplementation(libs.kotlin.junit) + testImplementation(libs.coroutines.test) + testImplementation(libs.h2db) } + tasks { test { useJUnitPlatform() diff --git a/hideout-mastodon/src/test/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/StatusQueryServiceImplTest.kt b/hideout-mastodon/src/test/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/StatusQueryServiceImplTest.kt new file mode 100644 index 00000000..a23dd3ef --- /dev/null +++ b/hideout-mastodon/src/test/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/StatusQueryServiceImplTest.kt @@ -0,0 +1,33 @@ +package dev.usbharu.hideout.mastodon.infrastructure.exposedquery + +import dev.usbharu.hideout.SpringApplication +import dev.usbharu.hideout.core.domain.model.actor.ActorId +import dev.usbharu.hideout.core.domain.model.support.acct.Acct +import dev.usbharu.hideout.core.domain.model.support.principal.FromApi +import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId +import kotlinx.coroutines.test.runTest +import org.junit.jupiter.api.Assertions.assertNull +import org.junit.jupiter.api.Test +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.test.context.jdbc.Sql +import org.springframework.transaction.annotation.Transactional + + +@Sql("/sql/actors.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) +@Sql("/sql/relationships.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) +@Transactional +@SpringBootTest(classes = [SpringApplication::class]) +class StatusQueryServiceImplTest { + + @Autowired + lateinit var statusQueryServiceImpl: StatusQueryServiceImpl + + @Test + fun フォロワー限定をフォロワー以外は見れない() = runTest { + val status = + statusQueryServiceImpl.findByPostId(4, FromApi(ActorId(1), UserDetailId(1), Acct("test", "example.com"))) + + assertNull(status) + } +} \ No newline at end of file diff --git a/hideout-mastodon/src/test/resources/application.yml b/hideout-mastodon/src/test/resources/application.yml new file mode 100644 index 00000000..05671a3f --- /dev/null +++ b/hideout-mastodon/src/test/resources/application.yml @@ -0,0 +1,12 @@ +spring: + datasource: + url: "jdbc:h2:mem:test;MODE=POSTGRESQL;DB_CLOSE_DELAY=-1;CASE_INSENSITIVE_IDENTIFIERS=true;TRACE_LEVEL_FILE=4;" + driver-class-name: org.h2.Driver +hideout: + url: "https://test-hideout-dev.usbharu.dev" + security: + jwt: + generate: true + key-id: a + private-key: "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC7VJTUt9Us8cKjMzEfYyjiWA4R4/M2bS1GB4t7NXp98C3SC6dVMvDuictGeurT8jNbvJZHtCSuYEvuNMoSfm76oqFvAp8Gy0iz5sxjZmSnXyCdPEovGhLa0VzMaQ8s+CLOyS56YyCFGeJZqgtzJ6GR3eqoYSW9b9UMvkBpZODSctWSNGj3P7jRFDO5VoTwCQAWbFnOjDfH5Ulgp2PKSQnSJP3AJLQNFNe7br1XbrhV//eO+t51mIpGSDCUv3E0DDFcWDTH9cXDTTlRZVEiR2BwpZOOkE/Z0/BVnhZYL71oZV34bKfWjQIt6V/isSMahdsAASACp4ZTGtwiVuNd9tybAgMBAAECggEBAKTmjaS6tkK8BlPXClTQ2vpz/N6uxDeS35mXpqasqskVlaAidgg/sWqpjXDbXr93otIMLlWsM+X0CqMDgSXKejLS2jx4GDjI1ZTXg++0AMJ8sJ74pWzVDOfmCEQ/7wXs3+cbnXhKriO8Z036q92Qc1+N87SI38nkGa0ABH9CN83HmQqt4fB7UdHzuIRe/me2PGhIq5ZBzj6h3BpoPGzEP+x3l9YmK8t/1cN0pqI+dQwYdgfGjackLu/2qH80MCF7IyQaseZUOJyKrCLtSD/Iixv/hzDEUPf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bwKfBstIs+bMY2Zkp18gnTxKLxoS2tFczGkPLPgizskuemMghRniWaoLcyehkd3qqGElvW/VDL5AaWTg0nLVkjRo9z+40RQzuVaE8AkAFmxZzow3x+VJYKdjykkJ0iT9wCS0DRTXu269V264Vf/3jvredZiKRkgwlL9xNAwxXFg0x/XFw005UWVRIkdgcKWTjpBP2dPwVZ4WWC+9aGVd+Gyn1o0CLelf4rEjGoXbAAEgAqeGUxrcIlbjXfbcmwIDAQAB" \ No newline at end of file diff --git a/hideout-mastodon/src/test/resources/sql/actors.sql b/hideout-mastodon/src/test/resources/sql/actors.sql new file mode 100644 index 00000000..cf62085d --- /dev/null +++ b/hideout-mastodon/src/test/resources/sql/actors.sql @@ -0,0 +1,35 @@ +insert into instance(id, name, description, url, icon_url, shared_inbox, software, version, is_blocked, is_muted, + moderation_note, created_at) +VALUES (1, 'instance', 'description', 'https://example.com', 'https://example.com', 'https://example.com', 'software', + 'version', false, false, 'note', current_timestamp) + , (2, 'instance', 'description', 'https://remote.example.com', 'https://example.com', 'https://remote.example.com', + 'software', + 'version', false, false, 'note', current_timestamp) + , (3, 'instance', 'description', 'https://remote2.example.com', 'https://example.com', + 'https://remote2.example.com', 'software', + 'version', false, false, 'note', current_timestamp); + +insert into actors(id, name, domain, screen_name, description, inbox, outbox, url, public_key, private_key, created_at, + key_id, following, followers, instance, locked, following_count, followers_count, posts_count, + last_post_at, last_update_at, suspend, move_to, icon, banner) +VALUES (1, 'test', 'example.com', 'test-actor', 'actor_description', 'https://example.com/test/inbox', + 'https://example.com/outbox', 'https://example.com/test', '---BEGIN PUBLIC KEY---', '---BEGIN PRIVATE KEY---', + current_timestamp, 'https://example.com/test#main-key', 'https://example.com/test/following', + 'https://example.com/test/followers', 1, false, 1, 0, 0, null, current_timestamp, false, null, null, null), + (2, 'test', 'remote.example.com', 'test-actor', 'actor_description', 'https://remote.example.com/test/inbox', + 'https://remote.example.com/outbox', 'https://remote.example.com', '---BEGIN PUBLIC KEY---', + '---BEGIN PRIVATE KEY---', + current_timestamp, 'https://remote.example.com/test#main-key', 'https://remote.example.com/test/following', + 'https://remote.example.com/test/followers', 2, false, 1, 0, 0, null, current_timestamp, false, null, null, + null), + (3, 'test', 'remote2.example.com', 'test-actor', 'actor_description', 'https://remote2.example.com/test/inbox', + 'https://remote2.example.com/test/outbox', 'https://remote2.example.com/test', '---BEGIN PUBLIC KEY---', + '---BEGIN PRIVATE KEY---', + current_timestamp, 'https://remote2.example.com/test#main-key', 'https://remote2.example.com/test/following', + 'https://example.com/followers', 3, false, 1, 0, 0, null, current_timestamp, false, null, null, null), + (4, 'test2', 'remote2.example.com', 'test-actor', 'actor_description', 'https://example.com/inbox', + 'https://remote2.example.com/test2/outbox', 'https://remote2.example.com/test2', '---BEGIN PUBLIC KEY---', + '---BEGIN PRIVATE KEY---', + current_timestamp, 'https://remote2.example.com/test2#main-key', 'https://remote2.example.com/test2/following', + 'https://remote2.example.com/test2/followers', 3, false, 1, 0, 0, null, current_timestamp, false, null, null, + null); \ No newline at end of file diff --git a/hideout-mastodon/src/test/resources/sql/posts.sql b/hideout-mastodon/src/test/resources/sql/posts.sql new file mode 100644 index 00000000..f8dec6b9 --- /dev/null +++ b/hideout-mastodon/src/test/resources/sql/posts.sql @@ -0,0 +1,15 @@ +insert into posts (id, actor_id, instance_id, overview, content, text, created_at, visibility, url, repost_id, reply_id, + sensitive, ap_id, deleted, hide, move_to) +values (1, 1, 1, null, 'content', 'text', current_timestamp, 'PUBLIC', 'https://example.com', null, null, false, + 'https://example.com', false, false, null), + (2, 2, 2, null, 'content', 'text', current_timestamp, 'FOLLOWERS', 'https://example.com', null, null, false, + 'https://example.com', false, false, null), + (3, 3, 1, null, 'content', 'text', current_timestamp, 'PUBLIC', 'https://example.com', null, null, false, + 'https://example.com', false, false, null), + (4, 4, 1, null, 'content', 'text', current_timestamp, 'FOLLOWERS', 'https://example.com', null, null, false, + 'https://example.com', false, false, null), + (5, 4, 1, null, 'content', 'text', current_timestamp, 'DIRECT', 'https://example.com', null, null, false, + 'https://example.com', false, false, null); + +insert into posts_visible_actors(post_id, actor_id) +VALUES (5, 2); \ No newline at end of file diff --git a/hideout-mastodon/src/test/resources/sql/relationships.sql b/hideout-mastodon/src/test/resources/sql/relationships.sql new file mode 100644 index 00000000..1470b2d9 --- /dev/null +++ b/hideout-mastodon/src/test/resources/sql/relationships.sql @@ -0,0 +1,5 @@ +insert into relationships(id, actor_id, target_actor_id, following, blocking, muting, follow_requesting, + muting_follow_request) +VALUES (1, 1, 2, true, false, false, false, false), + (2, 2, 1, true, false, false, false, false), + (3, 1, 3, false, true, false, false, false); \ No newline at end of file