generated from kevchuang/scala3-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): Add unit tests in CompanyService (#11)
- Loading branch information
Showing
5 changed files
with
125 additions
and
53 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
3 changes: 1 addition & 2 deletions
3
modules/server/src/main/scala/io/kevchuang/reviewboard/http/routes/HttpRoute.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
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
33 changes: 33 additions & 0 deletions
33
.../server/src/test/scala/io/kevchuang/reviewboard/services/company/CompanyServiceSpec.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,33 @@ | ||
package io.kevchuang.reviewboard.services.company | ||
|
||
import io.kevchuang.reviewboard.domain.company.* | ||
import io.kevchuang.reviewboard.services.utils.DataGenerator | ||
import zio.Scope | ||
import zio.test.* | ||
import io.github.iltotore.iron.* | ||
import io.kevchuang.reviewboard.services.db.{DatabaseService, InMemoryDatabase} | ||
|
||
object CompanyServiceSpec extends ZIOSpecDefault: | ||
override def spec: Spec[TestEnvironment with Scope, Any] = createCompanySuite | ||
|
||
private lazy val createCompanySuite = | ||
suite("createCompany")( | ||
test("should create and add a new Company to the database") { | ||
val companyName = CompanyName("Contentsquare") | ||
val companyUrl = Url("contentsquare.com") | ||
val createCompany = | ||
DataGenerator.generateCreateCompany(companyName, companyUrl) | ||
val expected = DataGenerator.generateCompany( | ||
id = CompanyId(1), | ||
slug = CompanySlug("contentsquare"), | ||
name = companyName, | ||
url = companyUrl | ||
) | ||
for | ||
company <- CompanyService.createCompany(createCompany) | ||
exists <- DatabaseService.existsCompany(companyName) | ||
yield assertTrue(company == expected, exists) | ||
end for | ||
}.provide(InMemoryDatabase.live, CompanyServiceLive.live) | ||
) | ||
end CompanyServiceSpec |
46 changes: 46 additions & 0 deletions
46
modules/server/src/test/scala/io/kevchuang/reviewboard/services/utils/DataGenerator.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,46 @@ | ||
package io.kevchuang.reviewboard.services.utils | ||
|
||
import io.kevchuang.reviewboard.domain.company.* | ||
|
||
object DataGenerator: | ||
def generateCreateCompany( | ||
name: CompanyName, | ||
url: Url, | ||
location: Option[LocationName] = None, | ||
country: Option[CountryName] = None, | ||
industry: Option[IndustryName] = None, | ||
image: Option[Url] = None, | ||
tags: List[TagName] = List.empty[TagName] | ||
): CreateCompany = | ||
CreateCompany( | ||
name = name, | ||
url = url, | ||
location = location, | ||
country = country, | ||
industry = industry, | ||
image = image, | ||
tags = tags | ||
) | ||
|
||
def generateCompany( | ||
id: CompanyId, | ||
slug: CompanySlug, | ||
name: CompanyName, | ||
url: Url, | ||
location: Option[LocationName] = None, | ||
country: Option[CountryName] = None, | ||
industry: Option[IndustryName] = None, | ||
image: Option[Url] = None, | ||
tags: List[TagName] = List.empty[TagName] | ||
): Company = Company( | ||
id = id, | ||
slug = slug, | ||
name = name, | ||
url = url, | ||
location = location, | ||
country = country, | ||
industry = industry, | ||
image = image, | ||
tags = tags | ||
) | ||
end DataGenerator |