Skip to content

Commit

Permalink
refactor(task): rename from CreateAuthor to CreateOrUpdateAuthor
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshinorin committed Jul 21, 2024
1 parent f980bd8 commit e9e58d4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ scalacOptions ++= Seq(
// https://github.com/rtimush/sbt-updates
dependencyAllowPreRelease := true

val createAuthor = inputKey[Unit]("create an author. args must be three. They are 'name', 'displayName' and 'password'")
val createOrUpdateAuthor = inputKey[Unit]("create an author. args must be three. They are 'name', 'displayName' and 'password'")
lazy val root = (project in file("."))
.settings(
createAuthor := Def.inputTaskDyn {
createOrUpdateAuthor := Def.inputTaskDyn {
import sbt.Def.spaceDelimited
val args = spaceDelimited("<args>").parsed
val task = (Compile / runMain).toTask(s" net.yoshinorin.qualtet.tasks.CreateAuthor ${args.mkString(" ")}")
val task = (Compile / runMain).toTask(s" net.yoshinorin.qualtet.tasks.CreateOrUpdateAuthor ${args.mkString(" ")}")
task
}.evaluated
)
Expand Down
4 changes: 2 additions & 2 deletions docs/_docs/development/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $ docker compose -f ./docker-compose.local.yml up

```sh
$ sbt
$ sbt:qualtet> createAuthor <name> <displayName> <password>
$ sbt:qualtet> createOrUpdateAuthor <name> <displayName> <password>
```

3. shut down docker once that runs seq `1.`
Expand All @@ -41,7 +41,7 @@ $ cd <source code dir>
$ sbt run
Multiple main classes detected. Select one to run:
[1] net.yoshinorin.qualtet.BootStrap
[2] net.yoshinorin.qualtet.tasks.CreateAuthor
[2] net.yoshinorin.qualtet.tasks.CreateOrUpdateAuthor

Enter number: 1
```
Expand Down
6 changes: 3 additions & 3 deletions docs/_docs/getting-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ $ sbt

...

$ sbt:qualtet> createAuthor <name> <displayName> <password>
$ sbt:qualtet> createOrUpdateAuthor <name> <displayName> <password>

// example
$ sbt:qualtet> createAuthor jhonDue JD pass
$ sbt:qualtet> createOrUpdateAuthor jhonDue JD pass

// result
2021-08-03 21:54:03 +0900 [INFO] from net.yoshinorin.qualtet.tasks.createAuthor$ - author created: {
2021-08-03 21:54:03 +0900 [INFO] from net.yoshinorin.qualtet.tasks.createOrUpdateAuthor$ - author created: {
"id" : "01fgvhkzpyghp23wvp4p87nx29",
"name" : "jhonDue",
"displayName" : "JD",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import net.yoshinorin.qualtet.domains.authors.ResponseAuthor

import cats.effect.unsafe.implicits.global

object CreateAuthor extends IOApp {
object CreateOrUpdateAuthor extends IOApp {

private val logger = LoggerFactory.getLogger(this.getClass)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ import net.yoshinorin.qualtet.fixture.Fixture.{author, author2, authorService}
import org.scalatest.wordspec.AnyWordSpec
import cats.effect.unsafe.implicits.global

// testOnly net.yoshinorin.qualtet.tasks.CreateAuthorSpec
class CreateAuthorSpec extends AnyWordSpec {
// testOnly net.yoshinorin.qualtet.tasks.CreateOrUpdateAuthorSpec
class CreateOrUpdateAuthorSpec extends AnyWordSpec {

"CreateAuthor" should {
"CreateOrUpdateAuthor" should {

"create author" in {
CreateAuthor.run(List(author.name.value, author.displayName.value, "pass")).unsafeRunSync()
CreateOrUpdateAuthor.run(List(author.name.value, author.displayName.value, "pass")).unsafeRunSync()

val a = authorService.findByName(AuthorName(author.name.value)).unsafeRunSync()
assert(a.get.name.value === author.name.value)

// NOTE: just for create test data
CreateAuthor.run(List(author2.name.value, author2.displayName.value, "pass")).unsafeRunSync()
CreateOrUpdateAuthor.run(List(author2.name.value, author2.displayName.value, "pass")).unsafeRunSync()
}

"not be create author" in {
assertThrows[IllegalArgumentException] {
CreateAuthor.run(List("testUser2", "tu")).unsafeRunSync()
CreateOrUpdateAuthor.run(List("testUser2", "tu")).unsafeRunSync()
}

val a = authorService.findByName(AuthorName("testUser2")).unsafeRunSync()
Expand Down

0 comments on commit e9e58d4

Please sign in to comment.