From 3c604abe37e0ed573fda5cdf1990dc975a926d74 Mon Sep 17 00:00:00 2001 From: usbharu Date: Sun, 11 May 2025 23:59:06 +0900 Subject: [PATCH] feat: persistence truncation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Postが切り詰められたかを永続化するように --- .../hideout/core/domain/model/post/Post.kt | 7 +- .../core/domain/model/post/PostContent.kt | 2 + .../exposed/PostResultRowMapper.kt | 3 +- .../ExposedPostRepository.kt | 5 +- .../resources/db/migration/V1__Init_DB.sql | 33 +- .../core/domain/model/post/PostContentTest.kt | 32 +- .../core/domain/model/post/TestPostFactory.kt | 4 +- .../ExposedPostRepositoryTest.kt | 544 ++---------------- .../ExposedReactionRepositoryTest.kt | 6 +- .../src/test/kotlin/utils/DbSetupUtil.kt | 27 + 10 files changed, 119 insertions(+), 544 deletions(-) create mode 100644 hideout/hideout-core/src/test/kotlin/utils/DbSetupUtil.kt diff --git a/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt b/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt index db5f2732..8e8cd76f 100644 --- a/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt +++ b/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt @@ -46,6 +46,7 @@ class Post( visibleActors: Set, hide: Boolean, moveTo: PostId?, + val wasTruncated: Boolean, ) : DomainEventStorable() { val actorId = actorId @@ -235,7 +236,8 @@ class Post( mediaIds = mediaIds, visibleActors = visibleActors, hide = hide, - moveTo = moveTo + moveTo = moveTo, + wasTruncated = wasTruncated ) } @@ -310,7 +312,8 @@ class Post( mediaIds = mediaIds, visibleActors = visibleActors, hide = hide, - moveTo = moveTo + moveTo = moveTo, + wasTruncated = content.wasTruncated ) post.addDomainEvent(PostDomainEventFactory(post).createEvent(PostEvent.CREATE)) return post diff --git a/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContent.kt b/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContent.kt index 28944d80..eb421ebd 100644 --- a/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContent.kt +++ b/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContent.kt @@ -23,8 +23,10 @@ class PostContent { val text: String val content: String val emojiIds: List + val wasTruncated: Boolean constructor(text: String, content: String, emojiIds: List) { + wasTruncated = text.length > TEXT_LENGTH || content.length > CONTENT_LENGTH this.text = text.take(TEXT_LENGTH) this.content = content.take(CONTENT_LENGTH) this.emojiIds = emojiIds.distinct() diff --git a/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/PostResultRowMapper.kt b/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/PostResultRowMapper.kt index fccc7166..2d8dd4ca 100644 --- a/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/PostResultRowMapper.kt +++ b/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/PostResultRowMapper.kt @@ -44,7 +44,8 @@ class PostResultRowMapper : ResultRowMapper { mediaIds = emptyList(), visibleActors = emptySet(), hide = resultRow[Posts.hide], - moveTo = resultRow[Posts.moveTo]?.let { PostId(it) } + moveTo = resultRow[Posts.moveTo]?.let { PostId(it) }, + wasTruncated = resultRow[Posts.wasTruncated] ) } } diff --git a/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt b/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt index a65b6155..dd3b5914 100644 --- a/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt +++ b/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt @@ -39,6 +39,7 @@ import dev.usbharu.hideout.core.infrastructure.exposedrepository.Posts.sensitive import dev.usbharu.hideout.core.infrastructure.exposedrepository.Posts.text import dev.usbharu.hideout.core.infrastructure.exposedrepository.Posts.url import dev.usbharu.hideout.core.infrastructure.exposedrepository.Posts.visibility +import dev.usbharu.hideout.core.infrastructure.exposedrepository.Posts.wasTruncated import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.SqlExpressionBuilder.inList @@ -123,6 +124,7 @@ class ExposedPostRepository( this[deleted] = it.deleted this[hide] = it.hide this[moveTo] = it.moveTo?.id + this[wasTruncated] = it.wasTruncated } val mediaIds = posts.flatMap { post -> post.mediaIds.map { post.id.id to it.id } } val postsIds = posts.map { it.id.id } @@ -296,10 +298,11 @@ object Posts : Table("posts") { val repostId = long("repost_id").references(id).nullable() val replyId = long("reply_id").references(id).nullable() val sensitive = bool("sensitive") - val apId = varchar("ap_id", 1000) + val apId = varchar("ap_id", 1000).uniqueIndex() val deleted = bool("deleted") val hide = bool("hide") val moveTo = long("move_to").references(id).nullable() + val wasTruncated = bool("was_truncated").default(false).clientDefault { false } override val primaryKey: PrimaryKey = PrimaryKey(id) } diff --git a/hideout/hideout-core/src/main/resources/db/migration/V1__Init_DB.sql b/hideout/hideout-core/src/main/resources/db/migration/V1__Init_DB.sql index 38395744..8ce6c211 100644 --- a/hideout/hideout-core/src/main/resources/db/migration/V1__Init_DB.sql +++ b/hideout/hideout-core/src/main/resources/db/migration/V1__Init_DB.sql @@ -149,22 +149,23 @@ alter table actors create table if not exists posts ( - id bigint primary key, - actor_id bigint not null, - instance_id bigint not null, - overview varchar(100) null, - content varchar(5000) not null, - text varchar(3000) not null, - created_at timestamp not null, - visibility varchar(100) not null, - url varchar(500) not null, - repost_id bigint null, - reply_id bigint null, - "sensitive" boolean default false not null, - ap_id varchar(100) not null unique, - deleted boolean default false not null, - hide boolean default false not null, - move_to bigint default null null + id bigint primary key, + actor_id bigint not null, + instance_id bigint not null, + overview varchar(100) null, + content varchar(5000) not null, + text varchar(3000) not null, + created_at timestamp not null, + visibility varchar(100) not null, + url varchar(500) not null, + repost_id bigint null, + reply_id bigint null, + "sensitive" boolean default false not null, + ap_id varchar(100) not null unique, + deleted boolean default false not null, + hide boolean default false not null, + move_to bigint default null null, + was_truncated boolean default false not null ); alter table posts add constraint fk_posts_instance_id__id foreign key (instance_id) references instance (id) on delete cascade on update cascade; diff --git a/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContentTest.kt b/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContentTest.kt index e0da8111..327e91ef 100644 --- a/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContentTest.kt +++ b/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContentTest.kt @@ -1,44 +1,48 @@ package dev.usbharu.hideout.core.domain.model.post -import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test class PostContentTest { @Test - fun textがtext_lengthを超える場合は切り取られる() { + fun textがtext_lengthを超える場合は切り取られてwasTruncatedがtrue() { val postContent = PostContent( "a".repeat(PostContent.TEXT_LENGTH + 1), "b".repeat(PostContent.CONTENT_LENGTH), emptyList() ) - assertEquals(postContent.text, "a".repeat(PostContent.TEXT_LENGTH)) - assertEquals(postContent.content, "b".repeat(PostContent.CONTENT_LENGTH)) - } - - @Test - fun contentがcontent_lengthを超える場合は切り取られる() { - val postContent = PostContent( - "a".repeat(PostContent.TEXT_LENGTH), - "b".repeat(PostContent.CONTENT_LENGTH + 1), - emptyList() - ) + assertTrue(postContent.wasTruncated) assertEquals(postContent.text, "a".repeat(PostContent.TEXT_LENGTH)) assertEquals(postContent.content, "b".repeat(PostContent.CONTENT_LENGTH)) } @Test - fun textとcontentがtext_lengthとcontent_lengthを超えない場合は変わらない() { + fun textがtext_lengthを超えない場合は変わらずwasTruncatedがfalse() { val postContent = PostContent( "a".repeat(PostContent.TEXT_LENGTH), "b".repeat(PostContent.CONTENT_LENGTH), emptyList() ) + assertFalse(postContent.wasTruncated) + assertEquals(postContent.text, "a".repeat(PostContent.TEXT_LENGTH)) assertEquals(postContent.content, "b".repeat(PostContent.CONTENT_LENGTH)) } + @Test + fun contentがcontent_lengthを超える場合は切り取られてwasTruncatedがtrue() { + val postContent = PostContent( + "a".repeat(PostContent.TEXT_LENGTH), + "b".repeat(PostContent.CONTENT_LENGTH + 1), + emptyList() + ) + assertTrue(postContent.wasTruncated) + + assertEquals(postContent.text, "a".repeat(PostContent.TEXT_LENGTH)) + assertEquals(postContent.content, "b".repeat(PostContent.CONTENT_LENGTH)) + } } \ No newline at end of file diff --git a/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/TestPostFactory.kt b/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/TestPostFactory.kt index 47b7e9e9..c6cb48c8 100644 --- a/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/TestPostFactory.kt +++ b/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/TestPostFactory.kt @@ -31,6 +31,7 @@ object TestPostFactory { hide: Boolean = false, moveTo: Long? = null, emojiIds: List = emptyList(), + wasTruncated: Boolean = false, ): Post { return Post( PostId(id), @@ -49,7 +50,8 @@ object TestPostFactory { mediaIds = mediaIds.map { MediaId(it) }, visibleActors = visibleActors.map { ActorId(it) }.toSet(), hide = hide, - moveTo = moveTo?.let { PostId(it) } + moveTo = moveTo?.let { PostId(it) }, + wasTruncated = wasTruncated ) } diff --git a/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepositoryTest.kt b/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepositoryTest.kt index 527212c2..6a726113 100644 --- a/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepositoryTest.kt +++ b/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepositoryTest.kt @@ -270,7 +270,8 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { "http://localhost:8081/users/a/posts/1832779994749734912", false, false, - null + null, + false ) } }.launch() @@ -329,7 +330,8 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { "http://localhost:8081/users/a/posts/1832779994749734912", false, false, - null + null, + false ) } insertInto(PostsMedia.tableName) { @@ -364,7 +366,9 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { deleted = false, mediaIds = listOf(MediaId(2)), visibleActors = setOf(ActorId(4)), - hide = false, moveTo = null + hide = false, + moveTo = null, + wasTruncated = false ) assertNotNull(actual) @@ -398,60 +402,9 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { execute(disableReferenceIntegrityConstraints) insertInto("public.posts") { columns(Posts.columns) - values( - 1, - 1832779978794602496, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/1832779994749734912", - 2, - 2, - false, - "http://localhost:8081/users/a/posts/1832779994749734912", - false, - false, - null - ) - values( - 2, - 1832779978794602496, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/18327739994749734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/18327793994749734912", - false, - false, - null - ) - values( - 3, - 1832779978794602496, - 1832779642545639424, - "", - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/183277399947494734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/183277939947493734912", - false, - false, - 2 - ) + postsValues(1) + postsValues(2) + postsValues(3) } }.launch() @@ -467,60 +420,9 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { execute(disableReferenceIntegrityConstraints) insertInto("public.posts") { columns(Posts.columns) - values( - 1, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/1832779994749734912", - 2, - 2, - false, - "http://localhost:8081/users/a/posts/1832779994749734912", - false, - false, - null - ) - values( - 2, - 2, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/18327739994749734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/18327793994749734912", - false, - false, - null - ) - values( - 3, - 1, - 1832779642545639424, - "", - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/183277399947494734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/183277939947493734912", - false, - false, - 2 - ) + postsValues(1) + postsValues(2, 2) + postsValues(3) } }.launch() @@ -536,65 +438,16 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { execute(disableReferenceIntegrityConstraints) insertInto("public.posts") { columns(Posts.columns) - values( - 1, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/1832779994749734912", - 2, - 2, - false, - "http://localhost:8081/users/a/posts/1832779994749734912", - false, - false, - null - ) - values( - 2, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-02T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/18327739994749734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/18327793994749734912", - false, - false, - null - ) - values( - 3, - 1, - 1832779642545639424, - "", - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-03T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/183277399947494734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/183277939947493734912", - false, - false, - 2 - ) + postsValues(1) + postsValues(2) + postsValues(3) } }.launch() val findAllById = repository.findByActorId(ActorId(1), Page.of(maxId = 3)) + findAllById.forEach(::println) + assertThat(findAllById) .hasSize(2) @@ -608,60 +461,9 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { execute(disableReferenceIntegrityConstraints) insertInto("public.posts") { columns(Posts.columns) - values( - 1, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/1832779994749734912", - 2, - 2, - false, - "http://localhost:8081/users/a/posts/1832779994749734912", - false, - false, - null - ) - values( - 2, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-02T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/18327739994749734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/18327793994749734912", - false, - false, - null - ) - values( - 3, - 1, - 1832779642545639424, - "", - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-03T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/183277399947494734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/183277939947493734912", - false, - false, - 2 - ) + postsValues(1) + postsValues(2) + postsValues(3) } }.launch() @@ -680,60 +482,9 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { execute(disableReferenceIntegrityConstraints) insertInto("public.posts") { columns(Posts.columns) - values( - 1, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/1832779994749734912", - 2, - 2, - false, - "http://localhost:8081/users/a/posts/1832779994749734912", - false, - false, - null - ) - values( - 2, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-02T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/18327739994749734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/18327793994749734912", - false, - false, - null - ) - values( - 3, - 1, - 1832779642545639424, - "", - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-03T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/183277399947494734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/183277939947493734912", - false, - false, - 2 - ) + postsValues(1) + postsValues(2) + postsValues(3) } }.launch() @@ -752,60 +503,9 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { execute(disableReferenceIntegrityConstraints) insertInto("public.posts") { columns(Posts.columns) - values( - 1, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/1832779994749734912", - 2, - 2, - false, - "http://localhost:8081/users/a/posts/1832779994749734912", - false, - false, - null - ) - values( - 2, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-02T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/18327739994749734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/18327793994749734912", - false, - false, - null - ) - values( - 3, - 1, - 1832779642545639424, - "", - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-03T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/183277399947494734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/183277939947493734912", - false, - false, - 2 - ) + postsValues(1) + postsValues(2) + postsValues(3) } }.launch() @@ -823,24 +523,7 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { execute(disableReferenceIntegrityConstraints) insertInto("public.posts") { columns(Posts.columns) - values( - 1, - 1832779978794602496, - 1832779642545639424, - "", - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/1832779994749734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/1832779994749734912", - false, - false, - null - ) + postsValues(1) } insertInto(PostsMedia.tableName) { columns(PostsMedia.columns) @@ -884,78 +567,10 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { execute(disableReferenceIntegrityConstraints) insertInto("public.posts") { columns(Posts.columns) - values( - 1, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/1832779994749734912", - 2, - 2, - false, - "http://localhost:8081/users/a/posts/1832779994749734912", - false, - false, - null - ) - values( - 2, - 2, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-02T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/18327739994749734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/18327793994749734912", - false, - false, - null - ) - values( - 3, - 1, - 1832779642545639424, - "", - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-03T00:00:00Z")), - "UNLISTED", - "http://localhost:8081/users/a/posts/183277399947494734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/183277939947493734912", - false, - false, - 2 - ) - values( - 4, - 1, - 1832779642545639424, - "", - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-04T00:00:00Z")), - "FOLLOWERS", - "http://localhost:8081/users/a/posts/1832773999474947343912", - null, - null, - false, - "http://localhost:8081/users/a/posts/1832779399474937349312", - false, - false, - 2 - ) + postsValues(1) + postsValues(2, 2) + postsValues(3, 2) + postsValues(4) } }.launch() @@ -975,42 +590,8 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { execute(disableReferenceIntegrityConstraints) insertInto("public.posts") { columns(Posts.columns) - values( - 1, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/1832779994749734912", - 2, - 2, - false, - "http://localhost:8081/users/a/posts/1832779994749734912", - false, - false, - null - ) - values( - 3, - 1, - 1832779642545639424, - "", - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-03T00:00:00Z")), - "UNLISTED", - "http://localhost:8081/users/a/posts/183277399947494734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/183277939947493734912", - false, - false, - 2 - ) + postsValues(1) + postsValues(3) } insertInto(PostsMedia.tableName) { columns(PostsMedia.columns) @@ -1087,42 +668,8 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { execute(disableReferenceIntegrityConstraints) insertInto("public.posts") { columns(Posts.columns) - values( - 1, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/1832779994749734912", - 2, - 2, - false, - "http://localhost:8081/users/a/posts/1832779994749734912", - false, - false, - null - ) - values( - 3, - 1, - 1832779642545639424, - "", - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-03T00:00:00Z")), - "UNLISTED", - "http://localhost:8081/users/a/posts/183277399947494734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/183277939947493734912", - false, - false, - 2 - ) + postsValues(1) + postsValues(3) } insertInto(PostsMedia.tableName) { columns(PostsMedia.columns) @@ -1168,24 +715,7 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { execute(disableReferenceIntegrityConstraints) insertInto("public.posts") { columns(Posts.columns) - values( - 1, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/1832779994749734912", - 2, - 2, - false, - "http://localhost:8081/users/a/posts/1832779994749734912", - false, - false, - null - ) + postsValues(1) } }.launch() diff --git a/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedReactionRepositoryTest.kt b/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedReactionRepositoryTest.kt index ab8c59c6..9620c63f 100644 --- a/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedReactionRepositoryTest.kt +++ b/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedReactionRepositoryTest.kt @@ -56,7 +56,8 @@ class ExposedReactionRepositoryTest : AbstractRepositoryTest(Reactions) { "https://example.com", false, false, - null + null, + false ) } insertInto("public.actors") { @@ -141,7 +142,8 @@ class ExposedReactionRepositoryTest : AbstractRepositoryTest(Reactions) { "https://example.com", false, false, - null + null, + false ) } insertInto("public.actors") { diff --git a/hideout/hideout-core/src/test/kotlin/utils/DbSetupUtil.kt b/hideout/hideout-core/src/test/kotlin/utils/DbSetupUtil.kt new file mode 100644 index 00000000..0b542fb9 --- /dev/null +++ b/hideout/hideout-core/src/test/kotlin/utils/DbSetupUtil.kt @@ -0,0 +1,27 @@ +package utils + +import com.ninja_squad.dbsetup.operation.Insert +import java.sql.Timestamp +import java.time.Instant + +fun Insert.Builder.postsValues(index: Long = 1, actor: Long = 1) { + values( + index, + actor, + 1832779642545639424, + null, + "

test

", + "test", + Timestamp.from(Instant.parse("2020-01-01T00:00:00Z").plusSeconds(index.toLong())), + "PUBLIC", + "http://localhost:8081/users/a/posts/1832779994749734912", + 2, + 2, + false, + "http://localhost:8081/users/a/posts/1832779994749734912$index", + false, + false, + null, + false + ) +} \ No newline at end of file