simpler server API
This commit is contained in:
parent
d6d479f853
commit
69e4448749
@ -354,7 +354,7 @@ class SuperloginClient<D, S : WithAdapter>(
|
|||||||
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
inline operator fun <reified D, S : WithAdapter> invoke(
|
inline operator fun <reified D,S : WithAdapter> invoke(
|
||||||
t: Parsec3Transport<S>,
|
t: Parsec3Transport<S>,
|
||||||
savedData: SuperloginData<D>? = null,
|
savedData: SuperloginData<D>? = null,
|
||||||
): SuperloginClient<D, S> {
|
): SuperloginClient<D, S> {
|
||||||
|
@ -10,7 +10,10 @@ import kotlin.random.Random
|
|||||||
fun randomACOLike(): ByteArray {
|
fun randomACOLike(): ByteArray {
|
||||||
return Random.nextBytes(117)
|
return Random.nextBytes(117)
|
||||||
}
|
}
|
||||||
inline fun <reified D, T : SLServerSession<D>, H : CommandHost<T>> AdapterBuilder<T, H>.superloginServer() {
|
inline fun <reified D, T : SLServerSession<D>, H : CommandHost<T>> AdapterBuilder<T, H>.superloginServer(
|
||||||
|
crossinline sessionBuilder: suspend ()->T
|
||||||
|
) {
|
||||||
|
newSession { sessionBuilder() }
|
||||||
addErrors(SuperloginExceptionsRegistry)
|
addErrors(SuperloginExceptionsRegistry)
|
||||||
val a2 = SuperloginServerApi<WithAdapter>()
|
val a2 = SuperloginServerApi<WithAdapter>()
|
||||||
on(a2.slGetNonce) { nonce }
|
on(a2.slGetNonce) { nonce }
|
||||||
|
@ -154,15 +154,17 @@ internal class WsServerKtTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class S1: WithAdapter()
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun changePasswordTest() {
|
fun changePasswordTest() {
|
||||||
embeddedServer(Netty, port = 8081, module = Application::testServerModule).start(wait = false)
|
embeddedServer(Netty, port = 8081, module = Application::testServerModule).start(wait = false)
|
||||||
|
|
||||||
runBlocking {
|
runBlocking {
|
||||||
val client = Parsec3WSClient("ws://localhost:8081/api/p3")
|
val client = Parsec3WSClient.withSession<S1>("ws://localhost:8081/api/p3")
|
||||||
|
|
||||||
val api = TestApiServer<WithAdapter>()
|
val api = TestApiServer<WithAdapter>()
|
||||||
val slc = SuperloginClient<TestData, WithAdapter>(client)
|
val slc = SuperloginClient<TestData, S1>(client)
|
||||||
assertEquals(LoginState.LoggedOut, slc.state.value)
|
assertEquals(LoginState.LoggedOut, slc.state.value)
|
||||||
var rt = slc.register("foo", "passwd", TestData("bar!"))
|
var rt = slc.register("foo", "passwd", TestData("bar!"))
|
||||||
assertIs<Registration.Result.Success>(rt)
|
assertIs<Registration.Result.Success>(rt)
|
||||||
@ -211,10 +213,9 @@ internal class WsServerKtTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun Application.testServerModule() {
|
fun Application.testServerModule() {
|
||||||
parsec3TransportServer(TestApiServer<SLServerSession<TestData>>()) {
|
parsec3TransportServer(TestApiServer<TestSession>()) {
|
||||||
// superloginServer(TestServerTraits,TestApiServer<SLServerSession<TestData>>()) {
|
// superloginServer(TestServerTraits,TestApiServer<SLServerSession<TestData>>()) {
|
||||||
newSession { TestSession() }
|
superloginServer { TestSession() }
|
||||||
superloginServer()
|
|
||||||
on(api.loginName) {
|
on(api.loginName) {
|
||||||
println("login name called. now we have $currentLoginName : $superloginData")
|
println("login name called. now we have $currentLoginName : $superloginData")
|
||||||
currentLoginName
|
currentLoginName
|
||||||
|
Loading…
Reference in New Issue
Block a user