-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve routing ergonomics by narrowing path
- Loading branch information
1 parent
fecc625
commit 7bcc90d
Showing
15 changed files
with
148 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,6 @@ erl_crash.dump | |
|
||
*.sqlite | ||
*.sqlite-* | ||
|
||
|
||
.lasso-marks-tracker |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import app/config | ||
import app/serializers/user_serializer | ||
import gleam/http | ||
import gleam/option | ||
import wisp | ||
|
||
fn handle_current_user(_req: wisp.Request, ctx: config.Context) { | ||
case ctx.user { | ||
option.Some(user) -> wisp.ok() |> wisp.json_body(user_serializer.run(user)) | ||
option.None -> wisp.not_found() | ||
} | ||
} | ||
|
||
pub fn controller(req: wisp.Request, ctx: config.Context) { | ||
case ctx.scoped_segments, req.method { | ||
["current"], http.Get -> handle_current_user(req, ctx) | ||
|
||
_, _ -> wisp.not_found() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import app/router | ||
import gleeunit | ||
import gleeunit/should | ||
import helpers/context | ||
import wisp/testing | ||
|
||
pub fn main() { | ||
gleeunit.main() | ||
} | ||
|
||
pub fn get_home_page_test() { | ||
let request = testing.get("/", []) | ||
let response = router.handle_request(request, context.get_connection()) | ||
|
||
response.status | ||
|> should.equal(200) | ||
|
||
response.headers | ||
|> should.equal([#("content-type", "text/html; charset=utf-8")]) | ||
|
||
response | ||
|> testing.string_body | ||
|> should.equal("Welcome to Okane") | ||
} | ||
|
||
pub fn post_home_page_test() { | ||
let request = testing.post("/", [], "a body") | ||
let response = router.handle_request(request, context.get_connection()) | ||
|
||
response.status | ||
|> should.equal(405) | ||
} | ||
|
||
pub fn page_not_found_test() { | ||
let request = testing.get("/nothing-here", []) | ||
let response = router.handle_request(request, context.get_connection()) | ||
|
||
response.status | ||
|> should.equal(404) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import app/router | ||
import gleeunit | ||
import gleeunit/should | ||
import helpers/context | ||
import wisp/testing | ||
|
||
pub fn main() { | ||
gleeunit.main() | ||
} | ||
|
||
pub fn sessions_register_missing_form_test() { | ||
let response = | ||
testing.post_form("/sessions/register", [], []) | ||
|> router.handle_request(context.get_connection()) | ||
|
||
response.status |> should.equal(400) | ||
} | ||
|
||
pub fn sessions_register_form_test() { | ||
let response = | ||
testing.post_form("/sessions/register", [], [ | ||
#("name", "zoro"), | ||
#("email", "[email protected]"), | ||
#("password", "123"), | ||
]) | ||
|> router.handle_request(context.get_connection()) | ||
|
||
response.status |> should.equal(201) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import app/config | ||
import gleam/option | ||
import sqlight | ||
|
||
pub fn get_connection() -> config.Context { | ||
use conn <- sqlight.with_connection(":memory:") | ||
|
||
config.Context(conn, option.None, []) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,10 @@ | ||
import app/config | ||
import app/router | ||
import gleam/option | ||
import gleeunit | ||
import gleeunit/should | ||
import sqlight | ||
import wisp/testing | ||
|
||
pub fn main() { | ||
gleeunit.main() | ||
} | ||
|
||
fn get_connection() -> config.Context { | ||
use conn <- sqlight.with_connection(":memory:") | ||
|
||
config.Context(conn, option.None) | ||
} | ||
|
||
pub fn get_home_page_test() { | ||
let request = testing.get("/", []) | ||
let response = router.handle_request(request, get_connection()) | ||
|
||
response.status | ||
|> should.equal(200) | ||
|
||
response.headers | ||
|> should.equal([#("content-type", "text/html")]) | ||
|
||
response | ||
|> testing.string_body | ||
|> should.equal("Welcome to Okane") | ||
} | ||
|
||
pub fn post_home_page_test() { | ||
let request = testing.post("/", [], "a body") | ||
let response = router.handle_request(request, get_connection()) | ||
|
||
response.status | ||
|> should.equal(405) | ||
} | ||
|
||
pub fn page_not_found_test() { | ||
let request = testing.get("/nothing-here", []) | ||
let response = router.handle_request(request, get_connection()) | ||
|
||
response.status | ||
|> should.equal(404) | ||
} | ||
|
||
pub fn page_session_show_test() { | ||
let request = testing.get("/session", []) | ||
|
||
let response = router.handle_request(request, get_connection()) | ||
|
||
response.status |> should.equal(200) | ||
|
||
response |> testing.string_body |> should.equal("Welcome Okane") | ||
pub fn base_test() { | ||
10 |> should.equal(10) | ||
} |