Skip to content

Commit

Permalink
update cats & downstream dependencies (#221)
Browse files Browse the repository at this point in the history
update cats & downstream dependencies
  • Loading branch information
pepegar committed Oct 4, 2019
2 parents 2b371f6 + 5f88384 commit d93765b
Show file tree
Hide file tree
Showing 29 changed files with 306 additions and 227 deletions.
10 changes: 10 additions & 0 deletions .mergify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pull_request_rules:
- name: automatically merge scala-steward's PRs
conditions:
- author=scala-steward
- status-success=Travis CI - Pull Request
actions:
merge:
method: merge
label:
add: [dependency-update]
90 changes: 51 additions & 39 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,25 @@ inThisBuild(
))

val Versions = Map(
"contextual" -> "1.1.0",
"circe" -> "0.11.1",
"monocle" -> "1.5.1-cats",
"atto" -> "0.6.5",
"cats" -> "1.6.1",
"cats-effect" -> "1.3.1",
"simulacrum" -> "0.19.0",
"scalatest" -> "3.0.5",
"scalacheck" -> "1.14.0",
"discipline" -> "0.11.1",
"macro-paradise" -> "2.1.1",
"kind-projector" -> "0.9.10",
"akka-http" -> "10.0.15",
"ahc" -> "2.1.2",
"mockito" -> "1.10.19"
"contextual" -> "1.2.1",
"circe" -> "0.12.1",
"monocle" -> "2.0.0",
"atto" -> "0.7.1",
"cats" -> "2.0.0",
"cats-effect" -> "2.0.0",
"simulacrum" -> "1.0.0",
"scalatest" -> "3.2.0-M1",
"scalacheck" -> "1.14.2",
"scalatestplusScalaCheck" -> "3.1.0.0-RC2",
"scalatestplusMockito" -> "1.0.0-SNAP5",
"discipline" -> "1.0.1",
"macro-paradise" -> "2.1.1",
"kind-projector" -> "0.10.3",
"akka-http" -> "10.1.10",
"akka-stream" -> "2.5.23",
"ahc" -> "2.10.3",
"apacheHttp" -> "4.5.10",
"mockito" -> "1.10.19"
)

val noPublishSettings = Seq(
Expand All @@ -44,38 +48,38 @@ val noPublishSettings = Seq(

val buildSettings = Seq(
organization := "com.pepegar",
scalaVersion := "2.12.5",
scalaVersion := "2.12.10",
licenses := Seq(("MIT", url("http://opensource.org/licenses/MIT"))),
crossScalaVersions := Seq("2.11.12", scalaVersion.value),
scalacOptions in (Compile, console) ~= filterConsoleScalacOptions,
scalacOptions in (Compile, doc) ~= filterConsoleScalacOptions,
scalafmtOnCompile in ThisBuild := true
)

val commonDependencies = Seq(
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-core" % Versions("cats"),
"org.typelevel" %%% "cats-free" % Versions("cats"),
"org.typelevel" %%% "alleycats-core" % Versions("cats"),
"com.propensive" %%% "contextual" % Versions("contextual"),
"org.typelevel" %%% "cats-effect" % Versions("cats-effect"),
"com.github.mpilquist" %%% "simulacrum" % Versions("simulacrum"),
"com.github.julien-truffaut" %%% "monocle-core" % Versions("monocle"),
"com.github.julien-truffaut" %%% "monocle-macro" % Versions("monocle"),
"org.tpolecat" %%% "atto-core" % Versions("atto"),
"com.github.julien-truffaut" %%% "monocle-law" % Versions("monocle") % Test,
"org.typelevel" %%% "cats-laws" % Versions("cats") % Test,
"org.typelevel" %%% "cats-testkit" % Versions("cats") % Test,
"org.scalatest" %%% "scalatest" % Versions("scalatest") % Test,
"org.scalacheck" %%% "scalacheck" % Versions("scalacheck") % Test,
"org.typelevel" %%% "discipline" % Versions("discipline") % Test
"org.typelevel" %%% "cats-core" % Versions("cats"),
"org.typelevel" %%% "cats-free" % Versions("cats"),
"org.typelevel" %%% "alleycats-core" % Versions("cats"),
"com.propensive" %%% "contextual" % Versions("contextual"),
"org.typelevel" %%% "cats-effect" % Versions("cats-effect"),
"org.typelevel" %%% "simulacrum" % Versions("simulacrum"),
"com.github.julien-truffaut" %%% "monocle-core" % Versions("monocle"),
"com.github.julien-truffaut" %%% "monocle-macro" % Versions("monocle"),
"org.tpolecat" %%% "atto-core" % Versions("atto"),
"com.github.julien-truffaut" %%% "monocle-law" % Versions("monocle") % Test,
"org.typelevel" %%% "cats-laws" % Versions("cats") % Test,
"org.typelevel" %%% "cats-testkit" % Versions("cats") % Test,
"org.scalatest" %%% "scalatest" % Versions("scalatest") % Test,
"org.scalacheck" %%% "scalacheck" % Versions("scalacheck") % Test,
"org.scalatestplus" %%% "scalatestplus-scalacheck" % Versions("scalatestplusScalaCheck") % Test,
"org.typelevel" %%% "discipline-core" % Versions("discipline") % Test
)
)

val compilerPlugins = Seq(
libraryDependencies ++= Seq(
compilerPlugin("org.scalamacros" %% "paradise" % Versions("macro-paradise") cross CrossVersion.full),
compilerPlugin("org.spire-math" %% "kind-projector" % Versions("kind-projector"))
compilerPlugin("org.typelevel" %% "kind-projector" % Versions("kind-projector"))
)
)

Expand Down Expand Up @@ -130,10 +134,11 @@ lazy val apache = project
.settings(compilerPlugins)
.settings(
libraryDependencies ++= Seq(
"org.apache.httpcomponents" % "httpclient" % "4.5.9"
"org.apache.httpcomponents" % "httpclient" % Versions("apacheHttp"),
"org.scalatestplus" %%% "scalatestplus-mockito" % Versions("scalatestplusMockito") % Test,
"org.mockito" % "mockito-all" % Versions("mockito") % Test
)
)
.settings(libraryDependencies += "org.mockito" % "mockito-all" % Versions("mockito") % Test)
.dependsOn(coreJVM)

lazy val akka = project
Expand All @@ -143,9 +148,13 @@ lazy val akka = project
.settings(commonDependencies)
.settings(compilerPlugins)
.settings(
libraryDependencies += "com.typesafe.akka" %% "akka-http" % Versions("akka-http")
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-http" % Versions("akka-http"),
"com.typesafe.akka" %% "akka-stream" % Versions("akka-stream"),
"org.mockito" % "mockito-all" % Versions("mockito") % Test,
"org.scalatestplus" %%% "scalatestplus-mockito" % Versions("scalatestplusMockito") % Test
)
)
.settings(libraryDependencies += "org.mockito" % "mockito-all" % Versions("mockito") % Test)
.dependsOn(coreJVM)

lazy val asynchttpclient = project
Expand All @@ -155,9 +164,12 @@ lazy val asynchttpclient = project
.settings(commonDependencies)
.settings(compilerPlugins)
.settings(
libraryDependencies += "org.asynchttpclient" % "async-http-client" % Versions("ahc")
libraryDependencies ++= Seq(
"org.asynchttpclient" % "async-http-client" % Versions("ahc"),
"org.scalatestplus" %%% "scalatestplus-mockito" % Versions("scalatestplusMockito") % Test,
"org.mockito" % "mockito-all" % Versions("mockito") % Test
)
)
.settings(libraryDependencies += "org.mockito" % "mockito-all" % Versions("mockito") % Test)
.dependsOn(coreJVM)

lazy val javadocIoUrl = settingKey[String]("the url of hammock documentation in http://javadoc.io")
Expand Down
15 changes: 8 additions & 7 deletions core/js/src/main/scala/hammock/fetch/Interpreter.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package hammock
package fetch

import cats.~>
import cats.effect._
import cats._
import cats.syntax.flatMap._
import cats.syntax.functor._
import io.scalajs.npm.nodefetch._
import scala.scalajs.js.Promise
import cats.syntax.show._
Expand All @@ -12,7 +14,7 @@ object Interpreter {

def apply[F[_]](implicit F: InterpTrans[F]): InterpTrans[F] = F

implicit def instance[F[_]: Async](
implicit def instance[F[_]: Async: ContextShift](
implicit nodeFetch: NodeFetch = io.scalajs.npm.nodefetch.NodeFetch): InterpTrans[F] = new InterpTrans[F] {

def trans: HttpF ~> F = new (HttpF ~> F) {
Expand All @@ -29,8 +31,8 @@ object Interpreter {
}
http match {
case Get(_) | Options(_) | Delete(_) | Head(_) | Options(_) | Trace(_) | Post(_) | Put(_) | Patch(_) =>
val hammockResponse = for {
response <- IO.fromFuture(IO {
for {
response <- Async.fromFuture(Async[F].delay {
val headers = http.req.headers.toJSDictionary
nodeFetch(
http.req.uri.show,
Expand All @@ -39,7 +41,7 @@ object Interpreter {
_.cata(
string => Some(string.content),
bytes => Some(bytes.content.map(_.toChar).mkString),
empty => None
_ => None
))
.map(body => new RequestOptions(body = body, headers = headers, method = method.name))
.getOrElse(
Expand All @@ -49,9 +51,8 @@ object Interpreter {
))
).toFuture
})
entity <- IO.fromFuture(IO(response.text().asInstanceOf[Promise[String]].toFuture))
entity <- Async.fromFuture(Async[F].delay(response.text().asInstanceOf[Promise[String]].toFuture))
} yield HttpResponse(Status.Statuses(response.status), response.headers.toMap, Entity.StringEntity(entity))
hammockResponse.to[F]
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions core/js/src/main/scala/hammock/js/Interpreter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package hammock
package js

import cats._
import cats.effect.{Async, IO}
import cats.implicits._
import cats.effect.{Async, ContextShift}
import cats.syntax.applicative._
import cats.syntax.flatMap._
import cats.syntax.functor._
import cats.syntax.show._
import org.scalajs.dom.ext.Ajax
import org.scalajs.dom.ext.Ajax.InputData
import java.nio.ByteBuffer
Expand All @@ -12,7 +15,7 @@ object Interpreter {

def apply[F[_]](implicit F: InterpTrans[F]): InterpTrans[F] = F

implicit def instance[F[_]: Async]: InterpTrans[F] = new InterpTrans[F] {
implicit def instance[F[_]: Async: ContextShift]: InterpTrans[F] = new InterpTrans[F] {
def trans: HttpF ~> F = {

def doReq(reqF: HttpF[HttpResponse]): F[HttpResponse] = {
Expand All @@ -27,9 +30,9 @@ object Interpreter {
val method = toMethod(reqF)

for {
responseFutureIO <- Async[F].pure(IO(Ajax(method.name, reqF.req.uri.show, data, timeout, headers, false, "")))
response <- IO.fromFuture(responseFutureIO).to[F]
responseHeaders <- parseHeaders(response.getAllResponseHeaders)
response <- Async.fromFuture(
Async[F].delay(Ajax(method.name, reqF.req.uri.show, data, timeout, headers, false, "")))
responseHeaders <- parseHeaders(response.getAllResponseHeaders)
status = Status.get(response.status)
body = response.responseText
} yield HttpResponse(status, responseHeaders, Entity.StringEntity(body))
Expand Down
14 changes: 12 additions & 2 deletions core/js/src/test/scala/hammock/fetch/InterpreterSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ package hammock
package fetch

import cats.effect.IO
import org.scalatest.{AsyncFlatSpec, Matchers}
import org.scalatest.matchers.should.Matchers
import org.scalatest.flatspec.AsyncFlatSpec
import scala.concurrent.ExecutionContextExecutor
import Interpreter._

class InterpreterSpec extends AsyncFlatSpec with Matchers {

behavior of "node.Interpreter.trans"

implicit override def executionContext: ExecutionContextExecutor =
scala.scalajs.concurrent.JSExecutionContext.Implicits.queue
implicit val cs = IO.contextShift(executionContext)

Seq(
("Options", (uri: Uri, headers: Map[String, String]) => Ops.options(uri, headers)),
("Get", (uri: Uri, headers: Map[String, String]) => Ops.get(uri, headers)),
Expand All @@ -22,7 +27,12 @@ class InterpreterSpec extends AsyncFlatSpec with Matchers {
) foreach {
case (method, operation) =>
it should s"get response from mocky with $method requests" in {
operation(uri"http://www.mocky.io/v2/5185415ba171ea3a00704eed", Map("mock" -> "header")) foldMap Interpreter[IO].trans unsafeToFuture () map (_.status.code shouldBe 200)
operation(uri"http://www.mocky.io/v2/5185415ba171ea3a00704eed", Map("mock" -> "header"))
.foldMap(Interpreter[IO].trans)
.unsafeToFuture
.map { resp =>
resp.status.code shouldBe 200
}
}
}
}
19 changes: 10 additions & 9 deletions core/shared/src/main/scala/hammock/Status.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import monocle.macros.Lenses

@Lenses case class Status(code: Int, text: String, description: String) {
def isInformational: Boolean = this.code / 100 == 1
def isSuccess: Boolean = this.code / 100 == 2
def isRedirection: Boolean = this.code / 100 == 3
def isClientError: Boolean = this.code / 100 == 4
def isServerError: Boolean = this.code / 100 == 5
def isSuccess: Boolean = this.code / 100 == 2
def isRedirection: Boolean = this.code / 100 == 3
def isClientError: Boolean = this.code / 100 == 4
def isServerError: Boolean = this.code / 100 == 5
}

object Status {
Expand Down Expand Up @@ -118,9 +118,10 @@ object Status {
422,
"Unprocessable Entity",
"The request was well-formed but was unable to be followed due to semantic errors.")
val Locked = Status(423, "Locked", "The resource that is being accessed is locked.")
val FailedDependency = Status(424, "Failed Dependency", "The request failed due to failure of a previous request.")
val UnorderedCollection = Status(425, "Unordered Collection", "The collection is unordered.")
val Locked = Status(423, "Locked", "The resource that is being accessed is locked.")
val FailedDependency = Status(424, "Failed Dependency", "The request failed due to failure of a previous request.")
val TooEarly =
Status(425, "Too Early", "The server is unwilling to risk processing a request that might be replayed.")
val UpgradeRequired = Status(426, "Upgrade Required", "The client should switch to a different protocol.")
val PreconditionRequired = Status(428, "Precondition Required", "The server requires the request to be conditional.")
val TooManyRequests =
Expand Down Expand Up @@ -218,7 +219,7 @@ object Status {
422 -> UnprocessableEntity,
423 -> Locked,
424 -> FailedDependency,
425 -> UnorderedCollection,
425 -> TooEarly,
426 -> UpgradeRequired,
428 -> PreconditionRequired,
429 -> TooManyRequests,
Expand All @@ -245,5 +246,5 @@ object Status {
def get(code: Int): Status = Statuses.getOrElse(code, Status(code, "Undefined", "Undefined StatusCode"))

implicit val show: Show[Status] = Show[Int].contramap(_.code)
implicit val eq: Eq[Status] = Eq.fromUniversalEquals
implicit val eq: Eq[Status] = Eq.fromUniversalEquals
}
Loading

0 comments on commit d93765b

Please sign in to comment.