Remove nuxt + 100 other things..

This commit is contained in:
2020-07-08 19:46:04 +02:00
parent 3b80ae051d
commit 44b463d9d5
132 changed files with 6202 additions and 10961 deletions
@@ -0,0 +1,257 @@
package integration.services
import am.ik.yavi.builder.ValidatorBuilder
import am.ik.yavi.core.CustomConstraint
import am.ik.yavi.core.Validator
import be.vandewalleh.entities.Note
import be.vandewalleh.features.Migration
import be.vandewalleh.mainModule
import be.vandewalleh.repositories.NoteRepository
import be.vandewalleh.repositories.UserRepository
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.util.StdDateFormat
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.readValue
import com.github.javafaker.Faker
import kotlinx.coroutines.runBlocking
import me.liuwj.ktorm.jackson.*
import org.amshove.kluent.*
import org.junit.jupiter.api.*
import org.kodein.di.DI
import org.kodein.di.bind
import org.kodein.di.instance
import org.kodein.di.singleton
import utils.KMariadbContainer
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class NoteRepositoryTest {
@Nested
inner class DB {
private val mariadb = KMariadbContainer().apply { start() }
private val kodein = DI {
import(mainModule, allowOverride = true)
bind(overrides = true) from singleton { mariadb.datasource() }
}
init {
val migration by kodein.instance<Migration>()
migration.migrate()
}
@Test
fun run() {
val userService by kodein.instance<UserRepository>()
val user = runBlocking { userService.create("test", "test")!! }
val noteService by kodein.instance<NoteRepository>()
val note = runBlocking {
noteService.create(
user.id,
Note {
this.title = "a note"
this.markdown =
"""
|# Title
|
|😝😝😝😝
|another line
""".trimMargin()
this.tags = listOf("a", "tag")
}
)
}
println(note)
val objectMapper = ObjectMapper().apply {
registerModule(JavaTimeModule())
registerModule(KtormModule())
disable(DeserializationFeature.ACCEPT_FLOAT_AS_INT)
dateFormat = StdDateFormat()
}
val json = objectMapper.writeValueAsString(note)
println(json)
}
@Test
fun `test tag list`() {
val userService by kodein.instance<UserRepository>()
val user = runBlocking { userService.create("test", "test")!! }
val user2 = runBlocking { userService.create("user2", "test")!! }
val noteService by kodein.instance<NoteRepository>()
runBlocking {
noteService.create(
user.id,
Note {
title = "test"
markdown = ""
tags = listOf("same")
}
)
noteService.create(
user.id,
Note {
title = "test2"
markdown = ""
tags = listOf("same")
}
)
noteService.create(
user.id,
Note {
title = "test3"
markdown = ""
tags = listOf("another")
}
)
noteService.create(
user2.id,
Note {
title = "test"
markdown = ""
tags = listOf("user2")
}
)
}
val user1Tags = runBlocking { noteService.getTags(user.id) }
user1Tags `should be equal to` listOf("same", "another")
val user2Tags = runBlocking { noteService.getTags(user2.id) }
user2Tags `should be equal to` listOf("user2")
}
@Test
fun `test patch note`() {
val noteService by kodein.instance<NoteRepository>()
val userService by kodein.instance<UserRepository>()
val user = runBlocking { userService.create(Faker().name().username(), "test") }!!
val note = runBlocking {
noteService.create(
user.id,
Note {
this.title = "title"
this.markdown = "old content"
this.tags = emptyList()
}
)
}
val get = runBlocking { noteService.find(user.id, note.uuid) }
runBlocking {
noteService.updateNote(
user.id,
Note {
uuid = note.uuid
title = "new title"
}
)
}
val updated = runBlocking { noteService.find(user.id, note.uuid) }
println("updated: $updated")
}
}
@Nested
inner class NoteValidation {
@Test
fun `test update constraints`() {
val fieldPresentConstraint = object : CustomConstraint<Note> {
override fun defaultMessageFormat() = "fmt {0} {1} {2}"
override fun messageKey() = "title|content|tags"
override fun test(note: Note): Boolean {
val hasTitle = note["title"] != null
val hasContent = note["content"] != null
val hasTags = note["tags"] != null && note.tags.isNotEmpty()
return hasTitle || hasContent || hasTags
}
}
val userValidator: Validator<Note> = ValidatorBuilder<Note>()
.constraintOnTarget(fieldPresentConstraint, "present")
.build()
userValidator.validate(
Note {
title = "this is a title"
}
).isValid `should be equal to` true
userValidator.validate(
Note {
markdown = "this is a title"
}
).isValid `should be equal to` true
userValidator.validate(
Note {
tags = emptyList()
}
).isValid `should be equal to` false
userValidator.validate(
Note {
tags = listOf("tags")
}
).isValid `should be equal to` true
userValidator.validate(
Note {
tags = listOf("tags")
title = "This is a title"
}
).isValid `should be equal to` true
userValidator.validate(
Note {
tags = listOf("tags")
title = "This is a title"
markdown =
"""
|# This is
|
|some markdown content
""".trimMargin()
}
).isValid `should be equal to` true
userValidator.validate(
Note {
tags = listOf("tags")
title = "This is a title"
markdown =
"""
|# This is
|
|some markdown content
""".trimMargin()
}
).isValid `should be equal to` true
userValidator.validate(Note()).isValid `should be equal to` false
}
}
@Nested
inner class NoteEntity {
@Test
fun `test entity`() {
val objectMapper = ObjectMapper().apply {
registerModule(JavaTimeModule())
registerModule(KtormModule())
disable(DeserializationFeature.ACCEPT_FLOAT_AS_INT)
dateFormat = StdDateFormat()
}
val note: Note = objectMapper.readValue("""{"uuid": "2007e4d7-2986-4188-bde1-b99916d94bad"}""")
println(note.uuid)
println(note.uuid::class.qualifiedName)
println(note.uuid.leastSignificantBits)
println(note.uuid.mostSignificantBits)
}
}
}
@@ -0,0 +1,66 @@
package integration.services
import be.vandewalleh.features.Migration
import be.vandewalleh.mainModule
import be.vandewalleh.repositories.UserRepository
import kotlinx.coroutines.runBlocking
import org.amshove.kluent.*
import org.junit.jupiter.api.*
import org.kodein.di.DI
import org.kodein.di.bind
import org.kodein.di.instance
import org.kodein.di.singleton
import utils.KMariadbContainer
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(MethodOrderer.OrderAnnotation::class)
class UserRepositoryTest {
private val mariadb = KMariadbContainer().apply { start() }
private val kodein = DI {
import(mainModule, allowOverride = true)
bind(overrides = true) from singleton { mariadb.datasource() }
}
private val userService by kodein.instance<UserRepository>()
init {
val migration by kodein.instance<Migration>()
migration.migrate()
}
@Test
@Order(1)
fun `test create user`() {
runBlocking {
val username = "hubert"
val password = "password"
userService.create(username, password)
val user = userService.find(username)
user `should not be` null
user?.username `should be equal to` username
}
}
@Test
@Order(2)
fun `test create same user`() {
runBlocking {
userService.create(username = "hubert", password = "password") `should be` null
}
}
@Test
@Order(3)
fun `test delete user`() {
runBlocking {
val id = userService.find("hubert")!!.id
userService.delete(id)
userService.find("hubert") `should be` null
userService.find(id) `should be` null
}
}
}