Add ktlint config

This commit is contained in:
2020-07-03 00:28:11 +02:00
parent fb471f8100
commit 9212d23933
19 changed files with 145 additions and 125 deletions
+111 -81
View File
@@ -47,15 +47,20 @@ class NoteServiceTest {
val user = runBlocking { userService.create("test", "test")!! }
val noteService by kodein.instance<NoteService>()
val note = runBlocking {
noteService.create(user.id, Note {
this.title = "a note"
this.content = """# Title
|
|😝😝😝😝
|another line
""".trimMargin()
this.tags = listOf("a", "tag")
})
noteService.create(
user.id,
Note {
this.title = "a note"
this.content =
"""
|# Title
|
|😝😝😝😝
|another line
""".trimMargin()
this.tags = listOf("a", "tag")
}
)
}
println(note)
@@ -78,26 +83,38 @@ class NoteServiceTest {
val noteService by kodein.instance<NoteService>()
runBlocking {
noteService.create(user.id, Note {
title = "test"
content = ""
tags = listOf("same")
})
noteService.create(user.id, Note {
title = "test2"
content = ""
tags = listOf("same")
})
noteService.create(user.id, Note {
title = "test3"
content = ""
tags = listOf("another")
})
noteService.create(user2.id, Note {
title = "test"
content = ""
tags = listOf("user2")
})
noteService.create(
user.id,
Note {
title = "test"
content = ""
tags = listOf("same")
}
)
noteService.create(
user.id,
Note {
title = "test2"
content = ""
tags = listOf("same")
}
)
noteService.create(
user.id,
Note {
title = "test3"
content = ""
tags = listOf("another")
}
)
noteService.create(
user2.id,
Note {
title = "test"
content = ""
tags = listOf("user2")
}
)
}
val user1Tags = runBlocking { noteService.getTags(user.id) }
user1Tags `should be equal to` listOf("same", "another")
@@ -111,27 +128,30 @@ class NoteServiceTest {
val userService by kodein.instance<UserService>()
val user = runBlocking { userService.create(Faker().name().username(), "test") }!!
val note = runBlocking {
noteService.create(user.id, Note {
this.title = "title"
this.content = "old content"
this.tags = emptyList()
})
noteService.create(
user.id,
Note {
this.title = "title"
this.content = "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"
})
noteService.updateNote(
user.id,
Note {
uuid = note.uuid
title = "new title"
}
)
}
val updated = runBlocking { noteService.find(user.id, note.uuid) }
println("updated: $updated")
}
}
@Nested
@@ -150,58 +170,70 @@ class NoteServiceTest {
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 {
title = "this is a title"
}
).isValid `should be equal to` true
userValidator.validate(Note {
content = "this is a title"
}).isValid `should be equal to` true
userValidator.validate(
Note {
content = "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 = 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")
}
).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"
}
).isValid `should be equal to` true
userValidator.validate(Note {
tags = listOf("tags")
title = "This is a title"
content = """
# This is
some markdown content
""".trimIndent()
}).isValid `should be equal to` true
userValidator.validate(
Note {
tags = listOf("tags")
title = "This is a title"
content =
"""
|# This is
|
|some markdown content
""".trimMargin()
}
).isValid `should be equal to` true
userValidator.validate(Note {
tags = listOf("tags")
title = "This is a title"
content = """
# This is
some markdown content
""".trimIndent()
}).isValid `should be equal to` true
userValidator.validate(
Note {
tags = listOf("tags")
title = "This is a title"
content =
"""
|# This is
|
|some markdown content
""".trimMargin()
}
).isValid `should be equal to` true
userValidator.validate(Note()).isValid `should be equal to` false
}
}
@Nested
@@ -222,6 +254,4 @@ class NoteServiceTest {
println(note.uuid.mostSignificantBits)
}
}
}
@@ -12,7 +12,6 @@ import org.kodein.di.instance
import org.kodein.di.singleton
import utils.KMariadbContainer
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(MethodOrderer.OrderAnnotation::class)
class UserServiceTest {
@@ -21,7 +20,7 @@ class UserServiceTest {
private val kodein = DI {
import(mainModule, allowOverride = true)
bind( overrides = true) from singleton { mariadb.datasource() }
bind(overrides = true) from singleton { mariadb.datasource() }
}
private val userService by kodein.instance<UserService>()
@@ -64,5 +63,4 @@ class UserServiceTest {
userService.find(id) `should be` null
}
}
}