mirror of
https://github.com/logos-storage/nim-json-rpc.git
synced 2026-01-06 15:43:13 +00:00
Add example test case that currently fails the Option parsing
This commit is contained in:
parent
76dd352ace
commit
f59e387da2
@ -162,6 +162,15 @@ s.rpc("rpc.optInObj") do(data: string, options: Option[MaybeOptions]) -> int:
|
||||
if o.o2.isSome: result += 2
|
||||
if o.o3.isSome: result += 4
|
||||
|
||||
proc installMoreApiHandlers*(s: RpcServer, prefix: static string) =
|
||||
s.rpc(prefix & ".optionalStringArg") do(a: Option[string]) -> string:
|
||||
if a.isSome:
|
||||
return a.get()
|
||||
else:
|
||||
return "nope"
|
||||
|
||||
s.installMoreApiHandlers("rpc")
|
||||
|
||||
# Tests
|
||||
suite "Server types":
|
||||
test "On macro registration":
|
||||
@ -178,6 +187,7 @@ suite "Server types":
|
||||
check s.hasMethod("rpc.mixedOptionalArg")
|
||||
check s.hasMethod("rpc.optionalArgNotBuiltin")
|
||||
check s.hasMethod("rpc.optInObj")
|
||||
check s.hasMethod("rpc.optionalStringArg")
|
||||
|
||||
test "Simple paths":
|
||||
let r = waitFor s.executeMethod("rpc.simplePath", %[])
|
||||
@ -329,5 +339,18 @@ suite "Server types":
|
||||
var r6 = waitFor s.executeMethod("rpc.optInObj", %[%"0x31ded", opts6])
|
||||
check r6 == JrpcConv.encode 3
|
||||
|
||||
test "Optional String Arg":
|
||||
let
|
||||
data = some("some string")
|
||||
r1 = waitFor s.executeMethod("rpc.optionalStringArg", %[%data])
|
||||
r2 = waitFor s.executeMethod("rpc.optionalStringArg", %[])
|
||||
r3 = waitFor s.executeMethod("rpc.optionalStringArg", %[newJNull()])
|
||||
echo r1
|
||||
echo r2
|
||||
echo r3
|
||||
check r1 == %data.get()
|
||||
check r2 == %"nope"
|
||||
check r3 == %"nope"
|
||||
|
||||
s.stop()
|
||||
waitFor s.closeWait()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user