Created
March 10, 2020 01:57
-
-
Save elyphas/a252ef08231648df85c10d30007f3905 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//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