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

Configure Feed

Select the types of activity you want to include in your feed.

:recycle: move sad path to other unit tests

Kacaii 384916fd 83d31c25

+86 -52
+35 -33
test/admin_test.gleam
··· 50 50 assert resp.status == 200 as "Response should be HTTP 200 OK" 51 51 52 52 let body = simulate.read_body(resp) 53 - let assert Ok(_) = 54 - json.parse(body, { 55 - // USER UUID Decoder 56 - let uuid_decoder = { 57 - use maybe_uuid <- decode.then(decode.string) 58 - case uuid.from_string(maybe_uuid) { 59 - Error(_) -> decode.failure(uuid.v7(), "uuid") 60 - Ok(value) -> decode.success(value) 61 - } 53 + let body_decoder = { 54 + // USER Uuid Decoder 55 + let uuid_decoder = { 56 + use maybe_uuid <- decode.then(decode.string) 57 + case uuid.from_string(maybe_uuid) { 58 + Error(_) -> decode.failure(uuid.v7(), "uuid") 59 + Ok(value) -> decode.success(value) 62 60 } 61 + } 63 62 64 - // USER ROLE DECODER 65 - let user_role_decoder = { 66 - use maybe_role <- decode.then(decode.string) 67 - case role.from_string_pt_br(maybe_role) { 68 - Error(_) -> decode.failure(role.Firefighter, "user_role") 69 - Ok(value) -> decode.success(value) 70 - } 63 + // User role decoder 64 + let user_role_decoder = { 65 + use maybe_role <- decode.then(decode.string) 66 + case role.from_string_pt_br(maybe_role) { 67 + Error(_) -> decode.failure(role.Firefighter, "user_role") 68 + Ok(value) -> decode.success(value) 71 69 } 70 + } 72 71 73 - use user_uuid <- decode.field("id", uuid_decoder) 74 - use full_name <- decode.field("full_name", decode.string) 75 - use email <- decode.field("email", decode.string) 76 - use user_role <- decode.field("user_role", user_role_decoder) 77 - use registration <- decode.field("registration", decode.string) 78 - use is_active <- decode.field("is_active", decode.bool) 72 + use user_uuid <- decode.field("id", uuid_decoder) 73 + use full_name <- decode.field("full_name", decode.string) 74 + use email <- decode.field("email", decode.string) 75 + use user_role <- decode.field("user_role", user_role_decoder) 76 + use registration <- decode.field("registration", decode.string) 77 + use is_active <- decode.field("is_active", decode.bool) 79 78 80 - //  ASSERT 81 - assert user_uuid == dummy_user_id as "Wrong user uudid" 82 - assert full_name == new_full_name as "Wrong user name" 83 - assert email == new_email as "Wrong user email" 84 - assert user_role == new_role as "Wrong user role" 85 - assert is_active == new_status as "Wrong user status" 86 - assert registration == new_registration as "Wrong user registration" 79 + //  ASSERT 80 + assert user_uuid == dummy_user_id as "Wrong user Uuid" 81 + assert full_name == new_full_name as "Wrong user name" 82 + assert email == new_email as "Wrong user email" 83 + assert user_role == new_role as "Wrong user role" 84 + assert is_active == new_status as "Wrong user status" 85 + assert registration == new_registration as "Wrong user registration" 86 + 87 + decode.success(Nil) 88 + } 87 89 88 - decode.success(Nil) 89 - }) 90 + let assert Ok(_) = json.parse(body, body_decoder) 90 91 91 92 // 󰃢 CLEANUP ---------------------------------------------------------------- 92 93 let assert Ok(deleted_user) = { ··· 101 102 102 103 pub fn update_user_status_test() { 103 104 let ctx = app_test.global_data() 105 + let base_path = "/admin/users/" 104 106 use _ <- list.each(list.range(1, app_test.n_tests)) 105 107 106 108 let dummy_user = dummy.random_user(ctx.db) 107 - let path = "/admin/users/" <> uuid.to_string(dummy_user) <> "/status" 109 + let path = base_path <> uuid.to_string(dummy_user) <> "/status" 108 110 109 111 let target_status = False 110 112 ··· 119 121 let req = app_test.with_authorization(req) 120 122 let resp = http_router.handle_request(req, ctx) 121 123 122 - assert resp.status == 200 as "Status should be 200" 124 + assert resp.status == 200 as "HTTP 200 OK" 123 125 let body = simulate.read_body(resp) 124 126 125 127 let assert Ok(_) =
+51 -19
test/occurrence_test.gleam
··· 304 304 let resp = http_router.handle_request(req, ctx) 305 305 306 306 assert resp.status == 401 as "Restricted to authenticated Users" 307 - let req = app_test.with_authorization(req) 308 - let resp = http_router.handle_request(req, ctx) 309 - let body = simulate.read_body(resp) 310 307 311 - let assert Ok(_) = 312 - json.parse(body, { 313 - let uuid_decoder = { 314 - use maybe_uuid <- decode.then(decode.string) 315 - case uuid.from_string(maybe_uuid) { 316 - Error(_) -> decode.failure(uuid.v7(), "occurrence_uuid") 317 - Ok(value) -> decode.success(value) 318 - } 308 + // Response decoder 309 + let resp_decoder = { 310 + let uuid_decoder = { 311 + use maybe_uuid <- decode.then(decode.string) 312 + case uuid.from_string(maybe_uuid) { 313 + Error(_) -> decode.failure(uuid.v7(), "occurrence_uuid") 314 + Ok(value) -> decode.success(value) 319 315 } 316 + } 320 317 321 - let resolved_at_decoder = decode.optional(decode.float) 318 + let resolved_at_decoder = decode.optional(decode.float) 322 319 323 - use occ_id <- decode.field("id", uuid_decoder) 324 - use resolved_at <- decode.field("resolved_at", resolved_at_decoder) 325 - use _ <- decode.field("updated_at", decode.float) 320 + use occ_id <- decode.field("id", uuid_decoder) 321 + use resolved_at <- decode.field("resolved_at", resolved_at_decoder) 322 + use _ <- decode.field("updated_at", decode.float) 326 323 327 - assert option.is_some(resolved_at) as "Occurrence should be closed" 328 - assert occ_id == dummy_occurrence as "Update the correct occurrence" 329 - decode.success(Nil) 330 - }) 324 + assert option.is_some(resolved_at) as "Occurrence should be closed" 325 + assert occ_id == dummy_occurrence as "Update the correct occurrence" 326 + decode.success(Nil) 327 + } 328 + 329 + let _happy_path = { 330 + let req = app_test.with_authorization(req) 331 + let resp = http_router.handle_request(req, ctx) 332 + let body = simulate.read_body(resp) 333 + 334 + let assert Ok(_) = json.parse(body, resp_decoder) 335 + as "Json response should be valid" 336 + } 331 337 332 338 // 󰃢 CLEANUP ---------------------------------------------------------------- 333 339 let assert Ok(_) = dev_sql.truncate_occurrence(ctx.db) 334 340 let assert Ok(_) = dev_sql.truncate_brigade(ctx.db) 335 341 let assert Ok(_) = dev_sql.soft_truncate_user_account(ctx.db) 342 + } 343 + 344 + pub fn resolve_missing_occurrence_test() { 345 + let ctx = app_test.global_data() 346 + let base_path = "/occurrence/resolved_at/" 347 + let path = base_path <> uuid.v7_string() 348 + 349 + let req = 350 + simulate.browser_request(http.Post, path) 351 + |> app_test.with_authorization() 352 + 353 + let resp = http_router.handle_request(req, ctx) 354 + assert resp.status == 404 as "Cant resolve missing occurrence" 336 355 } 337 356 338 357 pub fn reopen_occurrence_test() { ··· 392 411 let assert Ok(_) = dev_sql.truncate_brigade(ctx.db) 393 412 let assert Ok(_) = dev_sql.soft_truncate_user_account(ctx.db) 394 413 } 414 + 415 + pub fn reopen_missing_occurrence_test() { 416 + let ctx = app_test.global_data() 417 + let base_path = "/occurrence/resolved_at/" 418 + let path = base_path <> uuid.v7_string() 419 + 420 + let req = 421 + simulate.browser_request(http.Delete, path) 422 + |> app_test.with_authorization() 423 + 424 + let resp = http_router.handle_request(req, ctx) 425 + assert resp.status == 404 as "Cant reopen missing occurrence" 426 + }