wip: currently rewriting the project as a full stack application tangled.org/kacaii.dev/sigo
gleam

:beer: lower the number of tests runs

+32 -28
+20 -11
src/app/domain/brigade/register_new_brigade.gleam
··· 128 128 |> result.replace_error(NotFound), 129 129 ) 130 130 131 - use assigned_members <- result.map(try_assign_members( 131 + use assigned_members <- result.map(assign_members( 132 132 ctx:, 133 133 to: row.id, 134 134 assign: body.members_id, ··· 139 139 uuid.to_string(member) |> json.string 140 140 }) 141 141 142 + let created_at_json = 143 + timestamp.to_unix_seconds(row.created_at) 144 + |> json.float 145 + 146 + let id_json = 147 + uuid.to_string(row.id) 148 + |> json.string 149 + 142 150 json.to_string( 143 151 json.object([ 144 - #("id", json.string(uuid.to_string(row.id))), 145 - #("created_at", json.float(timestamp.to_unix_seconds(row.created_at))), 152 + #("id", id_json), 153 + #("created_at", created_at_json), 146 154 #("members", members_json), 147 155 ]), 148 156 ) 149 157 } 150 158 151 - fn try_assign_members( 159 + fn assign_members( 152 160 ctx ctx: Context, 153 161 assign members: List(uuid.Uuid), 154 162 to brigade_id: uuid.Uuid, ··· 163 171 row.inserted_user_id 164 172 } 165 173 166 - //  BROADCAST 167 - let registry = group_registry.get_registry(ctx.registry_name) 168 - list.each(assigned_members, fn(user_id) { 169 - let body = 170 - msg.Domain(msg.UserAssignedToBrigade(user_id: user_id, brigade_id:)) 171 - user.broadcast(registry, user_id, body) 172 - }) 174 + { 175 + //  BROADCAST ASSIGNMENT 176 + let registry = group_registry.get_registry(ctx.registry_name) 177 + use user_id <- list.each(assigned_members) 178 + 179 + msg.Domain(msg.UserAssignedToBrigade(user_id: user_id, brigade_id:)) 180 + |> user.broadcast(registry, user_id, _) 181 + } 173 182 174 183 assigned_members 175 184 }
+12 -17
test/app_test.gleam
··· 11 11 import wisp 12 12 import wisp/simulate 13 13 14 - pub const n_tests = 5 14 + pub const n_tests = 1 15 15 16 16 pub fn main() -> Nil { 17 17 gleeunit.main() ··· 19 19 20 20 /// Global context data used in unit tests 21 21 pub fn global_data() -> Context { 22 - global_value.create_with_unique_name("global_context", fn() { 23 - let db_process_name = process.new_name("db_conn") 24 - let registry_name = process.new_name("registry") 25 - let env = context.Dev 22 + use <- global_value.create_with_unique_name("global_context") 23 + 24 + let db_process_name = process.new_name("db_conn") 25 + let registry_name = process.new_name("registry") 26 + let env = context.Dev 26 27 27 - let assert Ok(config) = app.read_connection_url(db_process_name, env) 28 - let assert Ok(secret_key_base) = envoy.get("COOKIE_TOKEN") 28 + let assert Ok(config) = app.read_connection_url(db_process_name, env) 29 + let assert Ok(secret_key_base) = envoy.get("COOKIE_TOKEN") 29 30 30 - let db = pog.named_connection(db_process_name) 31 - let assert Ok(_) = pog.start(config) 31 + let db = pog.named_connection(db_process_name) 32 + let assert Ok(_) = pog.start(config) 32 33 33 - Context( 34 - static_directory: app.static_directory(), 35 - db:, 36 - registry_name:, 37 - secret_key_base:, 38 - env:, 39 - ) 40 - }) 34 + let static_directory = app.static_directory() 35 + Context(static_directory:, db:, registry_name:, secret_key_base:, env:) 41 36 } 42 37 43 38 ///  Create a request with admin privileges