-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added missing entities validations and tests
- Loading branch information
1 parent
08b54ea
commit af596b3
Showing
23 changed files
with
447 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: release-drafter | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
release_draft: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
steps: | ||
- uses: release-drafter/release-drafter@v5 | ||
with: | ||
config-name: release-drafter.yml | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GH_PAT }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
docker rm -f -v bookstore-db | ||
docker-compose up -d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/test/scala/com/example/books/domain/author/AuthorMother.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.example.books.domain.author | ||
|
||
import com.example.shared.domain.common.{Id, Name} | ||
import com.example.shared.domain.shared.{IdMother, TextMother} | ||
|
||
object AuthorMother { | ||
def apply( | ||
id: Id = IdMother.random, | ||
firstName: Name = Name(TextMother.random(25)), | ||
lastName: Name = Name(TextMother.random(25)) | ||
): Author = Author(id, firstName, lastName) | ||
|
||
def random: Author = apply() | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/scala/com/example/books/domain/book/BookMother.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.example.books.domain.book | ||
|
||
import com.example.shared.domain.common.Id | ||
import com.example.shared.domain.shared.{AlphaNumericMother, IdMother, TextMother} | ||
|
||
import java.time.LocalDate | ||
|
||
object BookMother { | ||
def apply( | ||
authorId: Id, | ||
publisherId: Id, | ||
id: Id = IdMother.random, | ||
title: BookTitle = BookTitle(TextMother.random(100)), | ||
isbn: BookIsbn = BookIsbn(AlphaNumericMother.random(30)), | ||
description: BookDescription = BookDescription(TextMother.random(500)), | ||
yearMother: BookYear = BookYear(LocalDate.now().getYear) | ||
): Book = Book(id, isbn, title, description, yearMother, publisherId, authorId) | ||
|
||
def random(authorId: Id, publisherId: Id): Book = apply(authorId, publisherId) | ||
} |
14 changes: 14 additions & 0 deletions
14
src/test/scala/com/example/books/domain/publisher/PublisherMother.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.example.books.domain.publisher | ||
|
||
import com.example.shared.domain.common.{Id, Name, URL} | ||
import com.example.shared.domain.shared.{IdMother, TextMother} | ||
|
||
object PublisherMother { | ||
def apply( | ||
id: Id = IdMother.random, | ||
name: Name = Name(TextMother.random(25)), | ||
url: URL = URL(s"www.${TextMother.random(10)}.com") | ||
): Publisher = Publisher(id, name, url) | ||
|
||
def random: Publisher = apply() | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/scala/com/example/books/infrastructure/helpers/AuthorHelper.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.example.books.infrastructure.helpers | ||
|
||
import com.example.books.domain.author.AuthorMother | ||
import com.example.shared.domain.common.Id | ||
import com.example.shared.infrastructure.http.HasHttp4sRoutesSuite | ||
|
||
trait AuthorHelper { | ||
self: HasHttp4sRoutesSuite => | ||
|
||
private lazy val authorService = module.authorService | ||
|
||
def createRandomAuthor: Id = { | ||
val author = AuthorMother.random | ||
authorService.create(author).unsafeRunSync() | ||
author.id | ||
} | ||
|
||
def deleteAuthor(id: Id): Unit = authorService.delete(id).unsafeRunSync() | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/test/scala/com/example/books/infrastructure/helpers/PublisherHelper.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.example.books.infrastructure.helpers | ||
|
||
import com.example.books.domain.publisher.PublisherMother | ||
import com.example.shared.domain.common.Id | ||
import com.example.shared.infrastructure.http.HasHttp4sRoutesSuite | ||
|
||
trait PublisherHelper { | ||
self: HasHttp4sRoutesSuite => | ||
|
||
private lazy val publisherService = module.publisherService | ||
|
||
def createRandomPublisher: Id = { | ||
val publisher = PublisherMother.random | ||
publisherService.create(publisher).unsafeRunSync() | ||
publisher.id | ||
} | ||
|
||
def deletePublisher(id: Id): Unit = publisherService.delete(id).unsafeRunSync() | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
src/test/scala/com/example/books/infrastructure/http/AuthorApiTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.example.books.infrastructure.http | ||
|
||
import cats.effect.IO | ||
import com.example.books.domain.author._ | ||
import com.example.books.infrastructure.codecs.AuthorCodecs | ||
import com.example.shared.domain.page.PageResponse | ||
import com.example.shared.domain.shared.IdMother | ||
import com.example.shared.infrastructure.http.{Fail, HasHttp4sRoutesSuite} | ||
import io.circe.generic.auto._ | ||
import org.http4s._ | ||
import org.http4s.circe.CirceEntityCodec._ | ||
|
||
import java.util.UUID | ||
|
||
class AuthorApiTest extends HasHttp4sRoutesSuite with AuthorCodecs { | ||
|
||
override val routes: HttpRoutes[IO] = module.authorApi.routes | ||
|
||
val author: Author = AuthorMother.random | ||
val authorId: UUID = author.id.value | ||
|
||
test(POST(author, uri"authors")).alias("CREATE") { response => | ||
assertEquals(response.status, Status.Created) | ||
} | ||
|
||
test(GET(uri"authors" / s"$authorId")).alias("FOUND") { response => | ||
assertEquals(response.status, Status.Ok) | ||
assertIO(response.as[Author], author) | ||
} | ||
|
||
lazy val notfoundId: UUID = IdMother.random.value | ||
|
||
test(GET(uri"authors" / s"$notfoundId")).alias("NOT_FOUND") { response => | ||
assertEquals(response.status, Status.NotFound) | ||
assertIO(response.as[Fail.NotFound], Fail.NotFound(s"Author for id: $notfoundId Not Found")) | ||
} | ||
|
||
test(GET(uri"authors")).alias("LIST") { response => | ||
assertEquals(response.status, Status.Ok) | ||
assertIO(response.as[PageResponse[Author]].map(_.elements.contains(author)), true) | ||
} | ||
|
||
lazy val updatedAuthor: Author = AuthorMother.random | ||
|
||
test(PUT(updatedAuthor, uri"authors" / s"$authorId")).alias("UPDATE") { response => | ||
assertEquals(response.status, Status.NoContent) | ||
} | ||
|
||
test(GET(uri"authors" / s"$authorId")).alias("UPDATED") { response => | ||
assertEquals(response.status, Status.Ok) | ||
assertIO(response.as[Author], updatedAuthor.copy(id = author.id)) | ||
} | ||
|
||
test(DELETE(uri"authors" / s"$authorId")).alias("EXISTS") { response => | ||
assertEquals(response.status, Status.NoContent) | ||
} | ||
|
||
test(DELETE(uri"authors" / s"$notfoundId")).alias("NOT EXISTS") { response => | ||
assertEquals(response.status, Status.NoContent) | ||
} | ||
|
||
} |
Oops, something went wrong.