-module(refrakt@testing). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/refrakt/testing.gleam"). -export([request/2, get/1, post/1, put/1, delete/1, with_header/3, with_body/2, assert_status/2, assert_header/3]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. -file("src/refrakt/testing.gleam", 50). ?DOC(" Create a request with a specific method and path.\n"). -spec request(gleam@http:method(), binary()) -> gleam@http@request:request(binary()). request(Method, Path) -> _pipe = gleam@http@request:new(), _pipe@1 = gleam@http@request:set_method(_pipe, Method), gleam@http@request:set_path(_pipe@1, Path). -file("src/refrakt/testing.gleam", 22). ?DOC(" Create a GET request for testing.\n"). -spec get(binary()) -> gleam@http@request:request(binary()). get(Path) -> _pipe = gleam@http@request:new(), _pipe@1 = gleam@http@request:set_method(_pipe, get), gleam@http@request:set_path(_pipe@1, Path). -file("src/refrakt/testing.gleam", 29). ?DOC(" Create a POST request for testing.\n"). -spec post(binary()) -> gleam@http@request:request(binary()). post(Path) -> _pipe = gleam@http@request:new(), _pipe@1 = gleam@http@request:set_method(_pipe, post), gleam@http@request:set_path(_pipe@1, Path). -file("src/refrakt/testing.gleam", 36). ?DOC(" Create a PUT request for testing.\n"). -spec put(binary()) -> gleam@http@request:request(binary()). put(Path) -> _pipe = gleam@http@request:new(), _pipe@1 = gleam@http@request:set_method(_pipe, put), gleam@http@request:set_path(_pipe@1, Path). -file("src/refrakt/testing.gleam", 43). ?DOC(" Create a DELETE request for testing.\n"). -spec delete(binary()) -> gleam@http@request:request(binary()). delete(Path) -> _pipe = gleam@http@request:new(), _pipe@1 = gleam@http@request:set_method(_pipe, delete), gleam@http@request:set_path(_pipe@1, Path). -file("src/refrakt/testing.gleam", 57). ?DOC(" Add a header to a test request.\n"). -spec with_header(gleam@http@request:request(binary()), binary(), binary()) -> gleam@http@request:request(binary()). with_header(Req, Name, Value) -> gleam@http@request:set_header(Req, Name, Value). -file("src/refrakt/testing.gleam", 66). ?DOC(" Set the body of a test request.\n"). -spec with_body(gleam@http@request:request(binary()), binary()) -> gleam@http@request:request(binary()). with_body(Req, Body) -> gleam@http@request:set_body(Req, Body). -file("src/refrakt/testing.gleam", 74). ?DOC(" Check that a response has a specific status code.\n"). -spec assert_status(gleam@http@response:response(binary()), integer()) -> boolean(). assert_status(Resp, Expected) -> erlang:element(2, Resp) =:= Expected. -file("src/refrakt/testing.gleam", 79). ?DOC(" Check that a response has a specific header value.\n"). -spec assert_header(gleam@http@response:response(binary()), binary(), binary()) -> boolean(). assert_header(Resp, Name, Expected) -> case gleam@http@response:get_header(Resp, Name) of {ok, Value} -> Value =:= Expected; {error, _} -> false end.