Skip to content

Instantly share code, notes, and snippets.

@elyphas
Created March 10, 2020 01:57
Show Gist options
  • Save elyphas/a252ef08231648df85c10d30007f3905 to your computer and use it in GitHub Desktop.
Save elyphas/a252ef08231648df85c10d30007f3905 to your computer and use it in GitHub Desktop.
//The function to test are these:
def testingTest(id: IdPedido): F[Either[String, GralDataPedido]]
def testingTest( id: IdPedido ): ApiFunction[Either[String, GralDataPedido ]] = Action { state =>
val pedido = new CGralDataPedido( )
pedido.byId(id).unsafeToFuture( )
}
class WebSocketSpec extends AsyncFreeSpec with Matchers with BeforeAndAfterAll {
implicit val system = ActorSystem("mycelium")
implicit val materializer = ActorMaterializer()
override def afterAll(): Unit = {
system.terminate()
()
}
"run" in {
import covenant.ws.api._
import monix.execution.Scheduler.Implicits.global
import spatutorial.shared.GralDataPedido
import covenantBackend.Covenant.{ApiImpl, Dsl, Event, State}
import share.covenantAPI.{Api, ApiError}
val port = 9991
val api = new WsApiConfigurationWithDefaults[Event, ApiError, State] {
override def dsl = Dsl
override def initialState: State = ""
override def isStateValid(state: State): Boolean = true
override def serverFailure(error: ServerFailure): ApiError = ApiError(error.toString)
}
object Backend {
val router = Router[ ByteBuffer, Dsl.ApiFunction ].route[ Api[ Dsl.ApiFunction ]]( ApiImpl )
def run() = {
val config = WebsocketServerConfig(bufferSize = 5, overflowStrategy = OverflowStrategy.fail)
val route = AkkaWsRoute.fromApiRouter(router, config, api)
Http().bindAndHandle(route, interface = "0.0.0.0", port = port)
}
}
object Frontend {
val config = WebsocketClientConfig()
val client = WsClient[ByteBuffer, Unit, ApiError](s"ws://localhost:$port/ws", config)
val api = client.sendWithDefault.wire[Api[Future]]
}
Backend.run()
for {
fun <- Frontend.api.testingTest( IdPedido( no_pedido = "0001", ejercicio = 2019 ) )
} yield {
println(fun)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment