🧚 A practical web framework for Gleam

Test empty response functions

+28 -9
+2 -5
src/wisp.gleam
··· 137 137 |> response.set_header("content-type", "text/html") 138 138 } 139 139 140 - // TODO: test 141 140 // TODO: document 142 141 pub fn method_not_allowed(permitted: List(Method)) -> Response { 143 142 let allowed = 144 143 permitted 145 144 |> list.map(http.method_to_string) 145 + |> list.sort(string.compare) 146 146 |> string.join(", ") 147 + |> string.uppercase 147 148 HttpResponse(405, [#("allow", allowed)], Empty) 148 149 } 149 150 150 - // TODO: test 151 151 // TODO: document 152 152 pub fn not_found() -> Response { 153 153 HttpResponse(404, [], Empty) 154 154 } 155 155 156 - // TODO: test 157 156 // TODO: document 158 157 pub fn bad_request() -> Response { 159 158 HttpResponse(400, [], Empty) 160 159 } 161 160 162 - // TODO: test 163 161 // TODO: document 164 162 pub fn entity_too_large() -> Response { 165 163 HttpResponse(413, [], Empty) 166 164 } 167 165 168 - // TODO: test 169 166 // TODO: document 170 167 pub fn internal_server_error() -> Response { 171 168 HttpResponse(500, [], Empty)
+26 -4
test/wisp_test.gleam
··· 1 1 import gleeunit 2 2 import gleeunit/should 3 + import wisp 4 + import gleam/http 5 + import gleam/http/response.{Response} 3 6 4 7 pub fn main() { 5 8 gleeunit.main() 6 9 } 7 10 8 - // gleeunit test functions end in `_test` 9 - pub fn hello_world_test() { 10 - 1 11 - |> should.equal(1) 11 + pub fn internal_server_error_test() { 12 + wisp.internal_server_error() 13 + |> should.equal(Response(500, [], wisp.Empty)) 14 + } 15 + 16 + pub fn entity_too_large_test() { 17 + wisp.entity_too_large() 18 + |> should.equal(Response(413, [], wisp.Empty)) 19 + } 20 + 21 + pub fn bad_request_test() { 22 + wisp.bad_request() 23 + |> should.equal(Response(400, [], wisp.Empty)) 24 + } 25 + 26 + pub fn not_found_test() { 27 + wisp.not_found() 28 + |> should.equal(Response(404, [], wisp.Empty)) 29 + } 30 + 31 + pub fn method_not_allowed_test() { 32 + wisp.method_not_allowed([http.Get, http.Patch, http.Delete]) 33 + |> should.equal(Response(405, [#("allow", "DELETE, GET, PATCH")], wisp.Empty)) 12 34 }