Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/Saturn/Router.fs
Original file line number Diff line number Diff line change
Expand Up @@ -207,33 +207,33 @@ module Router =

let lst =
choose [
for e in gets do
yield GET >=> e
for e in getsf do
yield GET >=> e
for e in gets do
yield GET >=> e

for e in posts do
yield POST >=> e
for e in postsf do
yield POST >=> e
for e in posts do
yield POST >=> e

for e in patches do
yield PATCH >=> e
for e in patchesf do
yield PATCH >=> e
for e in patches do
yield PATCH >=> e

for e in puts do
yield PUT >=> e
for e in putsf do
yield PUT >=> e
for e in puts do
yield PUT >=> e

for e in deletes do
yield DELETE >=> e
for e in deletesf do
yield DELETE >=> e
for e in deletes do
yield DELETE >=> e

yield! forwards
yield! forwardsf
yield! forwards
if state.NotFoundHandler.IsSome then
siteMap.NotFound ()
yield state.NotFoundHandler.Value
Expand Down
37 changes: 37 additions & 0 deletions tests/Saturn.UnitTests/RouterTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,40 @@ let caseInsensitiveTest =


]

let rootId = System.Guid.NewGuid()
let root = "roots"

let testForwardingRouter =
router {
forward $"/{root}" (fun next context ->
text $"{root}" next context
)
forwardf "/roots/%O" (fun id next context ->
text (sprintf "roots/%O" id) next context
)
}

[<Tests>]
let forwardingTests =
testList "Common root forwarding tests" [
testCase "FORWARD to `/ROOTS` returns `roots`" <| fun _ ->
let ctx = getEmptyContext "FORWARD" $"/{root}"
let expected = root
let result = testForwardingRouter next ctx |> runTask
match result with
| None -> failtestf "Result was expected to be %s" expected
| Some ctx ->
let body = (getBody ctx)
Expect.equal body expected "Result should be equal"

testCase $"FORWARD to `/ROOTS/{rootId}` returns `roots/{rootId}`" <| fun _ ->
let ctx = getEmptyContext "FORWARD" $"/{root}/{rootId}"
let expected = $"{root}/{rootId}"
let result = testForwardingRouter next ctx |> runTask
match result with
| None -> failtestf "Result was expected to be %s" expected
| Some ctx ->
let body = (getBody ctx)
Expect.equal body expected "Result should be equal"
]