Skip to content

Commit

Permalink
Add test for RepositoryJdbi.listAll
Browse files Browse the repository at this point in the history
  • Loading branch information
hermannm committed Sep 16, 2024
1 parent 41c7ace commit 44ed74c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/test/kotlin/no/liflig/documentstore/repository/ListTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,28 @@ package no.liflig.documentstore.repository
import kotlin.test.assertContains
import kotlin.test.assertEquals
import no.liflig.documentstore.testutils.exampleRepo
import no.liflig.documentstore.testutils.exampleRepoForListAll
import no.liflig.documentstore.testutils.exampleRepoWithStringId
import no.liflig.documentstore.testutils.examples.EntityWithStringId
import no.liflig.documentstore.testutils.examples.ExampleEntity
import no.liflig.documentstore.testutils.examples.ExampleStringId
import org.junit.jupiter.api.Test

class ListTest {
@Test
fun `test listAll`() {
val createdEntities = (0..9).map { number -> ExampleEntity(text = "list-all-test-${number}") }
for (entity in createdEntities) {
// Use create instead of batchCreate here, since we want to verify that they are sorted by
// createdAt
exampleRepoForListAll.create(entity)
}

val all = exampleRepoForListAll.listAll()
assertEquals(createdEntities.size, all.size)
assertEquals(createdEntities, all.map { it.item })
}

@Test
fun `test listByIds for UuidEntityId`() {
val (entity1, _) = exampleRepo.create(ExampleEntity(text = "Test 1"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ val exampleRepoWithCount: ExampleRepository by lazy {
ExampleRepository(jdbi, tableName = "example_with_count")
}

/** Separate table, to avoid other tests interfering with the list returned by listAll. */
val exampleRepoForListAll: ExampleRepository by lazy {
ExampleRepository(jdbi, tableName = "example_for_list_all")
}

val exampleRepoWithStringId: ExampleRepositoryWithStringEntityId by lazy {
ExampleRepositoryWithStringEntityId(jdbi)
}
Expand Down
14 changes: 12 additions & 2 deletions src/test/resources/db/migrations/V001__initial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ CREATE TABLE example_with_count
);
CREATE INDEX example_with_count_text_index ON "example_with_count" ((data ->> 'text'));

CREATE TABLE example_for_migration
CREATE TABLE example_for_list_all
(
id uuid NOT NULL PRIMARY KEY,
created_at timestamptz NOT NULL,
modified_at timestamptz NOT NULL,
version bigint NOT NULL,
data jsonb NOT NULL
);
CREATE INDEX example_for_migration_text_index ON "example_for_migration" ((data ->> 'text'));
CREATE INDEX example_for_list_all_text_index ON "example_for_list_all" ((data ->> 'text'));

CREATE TABLE example_with_string_id
(
Expand All @@ -39,3 +39,13 @@ CREATE TABLE example_with_string_id
data jsonb NOT NULL
);
CREATE INDEX example_with_string_id_text_index ON "example_with_string_id" ((data ->> 'text'));

CREATE TABLE example_for_migration
(
id uuid NOT NULL PRIMARY KEY,
created_at timestamptz NOT NULL,
modified_at timestamptz NOT NULL,
version bigint NOT NULL,
data jsonb NOT NULL
);
CREATE INDEX example_for_migration_text_index ON "example_for_migration" ((data ->> 'text'));

0 comments on commit 44ed74c

Please sign in to comment.