Refactor save return type without Either

This commit is contained in:
Guntis Smaukstelis
2023-06-22 13:59:44 +03:00
parent 1abb12d92a
commit 3e1635d494
8 changed files with 84 additions and 21 deletions
+23
View File
@@ -4,6 +4,7 @@ import cats.effect.unsafe.implicits.global
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
import java.io.IOException
import java.time.format.DateTimeFormatter
import java.time.{LocalDate, LocalDateTime}
@@ -32,4 +33,26 @@ class DBServiceSpec extends AnyFunSuite with Matchers {
lines.length shouldBe 2142
}
test("DBService.save should return correct result") {
val dbService = DBService.of.unsafeRunSync()
val fileName = "testFile.txt"
val fileContent = "test content..."
dbService.save(fileName, fileContent).unsafeRunSync() shouldEqual fileName
}
test("DBService.save returns error on invalid file name") {
val dbService = DBService.of.unsafeRunSync()
val fileName = "/invalid/file/name"
val fileContent = "test content..."
val result = dbService.save(fileName, fileContent).attempt.unsafeRunSync()
result match {
case Left(e) =>
assert(e.isInstanceOf[IOException])
case Right(_) => fail("Expected failure did not occur")
}
}
}