๐Ÿ‘ฉโ€๐Ÿš’ Firefighters API written in Gleam!
lustre gleam

:technologist: run unit tests inside a transaction

kacaii.dev b199e523 75bc171e

verified
+17 -8
+3 -3
server/test/auth_test.gleam
··· 3 3 import gleam/json 4 4 import server/router 5 5 import server/seed 6 - import server_test.{with_context} 6 + import server_test 7 7 import shared/contract/login as login_contract 8 8 import shared/contract/signup as signup_contract 9 9 import shared/role ··· 12 12 import wisp/simulate 13 13 14 14 pub fn login_test() { 15 - use ctx <- with_context() 15 + use ctx <- server_test.with_test_context() 16 16 let url = "/api/login" 17 17 18 18 let body = ··· 29 29 } 30 30 31 31 pub fn signup_test() { 32 - use ctx <- with_context() 32 + use ctx <- server_test.with_test_context() 33 33 let url = "/api/signup" 34 34 35 35 let body =
+14 -5
server/test/server_test.gleam
··· 16 16 gleeunit.main() 17 17 } 18 18 19 - pub fn with_context(next: fn(Context) -> a) -> a { 20 - let ctx = { 21 - use <- global_value.create_with_unique_name("context") 22 - 19 + fn global_context() -> Context { 20 + global_value.create_with_unique_name("server_test.global.data", fn() { 23 21 let db_process_name = process.new_name("db_conn") 24 22 let db = pog.named_connection(db_process_name) 25 23 ··· 32 30 let assert Ok(_result) = seed.germinate(ctx) 33 31 34 32 ctx 33 + }) 34 + } 35 + 36 + pub fn with_test_context(next: fn(Context) -> a) -> Nil { 37 + let ctx = global_context() 38 + let transaction = fn(db) { 39 + next(Context(..ctx, db:)) 40 + Error(Nil) 35 41 } 36 42 37 - next(ctx) 43 + let assert Error(pog.TransactionRolledBack(Nil)) = 44 + pog.transaction(ctx.db, transaction) 45 + 46 + Nil 38 47 } 39 48 40 49 pub fn with_authorization(