tangled
alpha
login
or
join now
kacaii.dev
/
sigo
0
fork
atom
๐ฉโ๐ Firefighters API written in Gleam!
lustre
gleam
0
fork
atom
overview
issues
pulls
pipelines
:technologist: run unit tests inside a transaction
kacaii.dev
2 weeks ago
b199e523
75bc171e
verified
This commit was signed with the committer's
known signature
.
kacaii.dev
SSH Key Fingerprint:
SHA256:n9v7QGNWHCUv1x/483hCtPUvTsVabU5PzC5CSJMUNtI=
+17
-8
2 changed files
expand all
collapse all
unified
split
server
test
auth_test.gleam
server_test.gleam
+3
-3
server/test/auth_test.gleam
···
3
3
import gleam/json
4
4
import server/router
5
5
import server/seed
6
6
-
import server_test.{with_context}
6
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
15
-
use ctx <- with_context()
15
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
32
-
use ctx <- with_context()
32
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
19
-
pub fn with_context(next: fn(Context) -> a) -> a {
20
20
-
let ctx = {
21
21
-
use <- global_value.create_with_unique_name("context")
22
22
-
19
19
+
fn global_context() -> Context {
20
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
33
+
})
34
34
+
}
35
35
+
36
36
+
pub fn with_test_context(next: fn(Context) -> a) -> Nil {
37
37
+
let ctx = global_context()
38
38
+
let transaction = fn(db) {
39
39
+
next(Context(..ctx, db:))
40
40
+
Error(Nil)
35
41
}
36
42
37
37
-
next(ctx)
43
43
+
let assert Error(pog.TransactionRolledBack(Nil)) =
44
44
+
pog.transaction(ctx.db, transaction)
45
45
+
46
46
+
Nil
38
47
}
39
48
40
49
pub fn with_authorization(