File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -362,6 +362,49 @@ defmodule BypassTest do
362362 end )
363363 end
364364
365+ test "Bypass.stub/4 does not raise if request with parameters is made" do
366+ :stub |> specific_route_with_params
367+ end
368+
369+ test "Bypass.expect/4 can be used to define a specific route with parameters" do
370+ :expect |> specific_route_with_params
371+ end
372+
373+ test "Bypass.expect_once/4 can be used to define a specific route with parameters" do
374+ :expect_once |> specific_route_with_params
375+ end
376+
377+ defp specific_route_with_params ( expect_fun ) do
378+ bypass = Bypass . open ( )
379+ method = "POST"
380+ pattern = "/this/:resource/get/:id"
381+ path = "/this/my_resource/get/1234"
382+
383+ # one of Bypass.expect or Bypass.expect_once
384+ apply ( Bypass , expect_fun , [
385+ bypass ,
386+ method ,
387+ pattern ,
388+ fn conn ->
389+ assert conn . method == method
390+ assert conn . request_path == path
391+
392+ assert conn . params == % {
393+ "resource" => "my_resource" ,
394+ "id" => "1234" ,
395+ "q_param_1" => "a" ,
396+ "q_param_2" => "b"
397+ }
398+
399+ Plug.Conn . send_resp ( conn , 200 , "" )
400+ end
401+ ] )
402+
403+ capture_log ( fn ->
404+ assert { :ok , 200 , "" } = request ( bypass . port , path <> "?q_param_1=a&q_param_2=b" )
405+ end )
406+ end
407+
365408 test "All routes to a Bypass.expect/4 call must be called" do
366409 :expect |> all_routes_must_be_called
367410 end
You can’t perform that action at this time.
0 commit comments