Flatten packages
Remove modules prefix
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package be.simplenotes.persistance
|
||||
|
||||
import be.simplenotes.config.DataSourceConfig
|
||||
import io.micronaut.context.BeanContext
|
||||
import org.flywaydb.core.Flyway
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import javax.sql.DataSource
|
||||
|
||||
abstract class DbTest {
|
||||
|
||||
abstract fun dataSourceConfig(): DataSourceConfig
|
||||
|
||||
val beanContext = BeanContext.build()
|
||||
|
||||
inline fun <reified T> BeanContext.getBean(): T = getBean(T::class.java)
|
||||
|
||||
@BeforeAll
|
||||
fun setComponent() {
|
||||
beanContext.registerSingleton(dataSourceConfig())
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
fun beforeEach() {
|
||||
val migration = beanContext.getBean<DbMigrations>()
|
||||
val dataSource = beanContext.getBean<DataSource>()
|
||||
|
||||
Flyway.configure()
|
||||
.dataSource(dataSource)
|
||||
.load()
|
||||
.clean()
|
||||
|
||||
migration.migrate()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package be.simplenotes.persistance.notes
|
||||
|
||||
import be.simplenotes.persistance.repositories.NoteRepository
|
||||
import be.simplenotes.types.*
|
||||
import com.github.javafaker.Faker
|
||||
import java.util.*
|
||||
|
||||
private val faker = Faker()
|
||||
|
||||
fun fakeUuid() = UUID.randomUUID()!!
|
||||
fun fakeTitle() = faker.lorem().characters(3, 50)!!
|
||||
fun tagGenerator() = generateSequence { faker.lorem().word() }
|
||||
fun fakeTags() = tagGenerator().take(faker.random().nextInt(0, 3)).toList()
|
||||
fun fakeContent() = faker.lorem().paragraph(faker.random().nextInt(0, 3))!!
|
||||
fun fakeNote() = Note(NoteMetadata(fakeTitle(), fakeTags()), fakeContent(), fakeContent())
|
||||
|
||||
fun PersistedNote.toPersistedMeta() =
|
||||
PersistedNoteMetadata(meta.title, meta.tags, updatedAt, uuid)
|
||||
|
||||
fun NoteRepository.insertFakeNote(
|
||||
userId: Int,
|
||||
title: String,
|
||||
tags: List<String> = emptyList(),
|
||||
md: String = "md",
|
||||
html: String = "html",
|
||||
): PersistedNote = create(userId, Note(NoteMetadata(title, tags), md, html))
|
||||
|
||||
fun NoteRepository.insertFakeNote(
|
||||
user: PersistedUser,
|
||||
title: String = fakeTitle(),
|
||||
tags: List<String> = fakeTags(),
|
||||
md: String = fakeContent(),
|
||||
html: String = fakeContent(),
|
||||
): PersistedNote = insertFakeNote(user.id, title, tags, md, html)
|
||||
|
||||
fun NoteRepository.insertFakeNotes(user: PersistedUser, count: Int): List<PersistedNote> =
|
||||
generateSequence { insertFakeNote(user) }.take(count).toList()
|
||||
@@ -0,0 +1,14 @@
|
||||
package be.simplenotes.persistance.users
|
||||
|
||||
import be.simplenotes.persistance.repositories.UserRepository
|
||||
import be.simplenotes.types.PersistedUser
|
||||
import be.simplenotes.types.User
|
||||
import com.github.javafaker.Faker
|
||||
|
||||
private val faker = Faker()
|
||||
|
||||
fun fakeUser() = User(faker.name().username(), faker.internet().password())
|
||||
|
||||
fun UserRepository.createFakeUser(): PersistedUser? {
|
||||
return create(fakeUser())
|
||||
}
|
||||
Reference in New Issue
Block a user