chore: run all tests · susaglam/cli@f5e04aa · GitHub
Skip to content

Commit f5e04aa

Browse files
committed
chore: run all tests
1 parent 1460d92 commit f5e04aa

8 files changed

Lines changed: 70 additions & 20 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 5 deletions

‎tests/README.md‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
## End-to-End tests from client lib to local stack
22

3-
### Auth test
3+
1. Start local stack
44

5-
1. Run user signup tests
5+
```bash
6+
supabase --workdir tests start
7+
```
8+
9+
2. Run all tests
610

711
```bash
8-
./tests/auth.sh
12+
./tests/all.sh supabase
913
```
1014

11-
### PostgREST test
15+
### Auth test
1216

13-
1. Create todos table
17+
1. Run user signup tests
1418

1519
```bash
16-
supabase --workdir tests migrations up
20+
./tests/auth.sh
1721
```
1822

19-
2. Run RLS policy tests
23+
### PostgREST test
24+
25+
1. Run RLS policy tests
2026

2127
```bash
2228
./tests/postgrest.sh

‎tests/all.sh‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
set -eou pipefail
3+
4+
dotenv=$("$@" --workdir tests status -o env)
5+
source <(echo "$dotenv" | sed 's/^/export /')
6+
7+
./tests/auth.sh
8+
./tests/postgrest.sh
9+
./tests/storage.sh
10+
./tests/realtime.sh
11+
./tests/edge-runtime.sh

‎tests/auth.sh‎

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/bin/bash
22
set -eou pipefail
33

4-
# 1. Publishable and secret keys are accepted as `apikey` header
4+
echo "Running Auth tests..."
5+
6+
# 1. Create user with publishable key
57
output=$(curl 'http://127.0.0.1:54321/auth/v1/signup' \
68
-H 'apikey: sb_publishable_ACJWlzQHlZjBrEguHvfOxg_3BJgxAaH' \
79
-H 'Content-Type: application/json' \
@@ -13,9 +15,21 @@ if [[ $(echo "$output" | jq -r '.user.role') != 'authenticated' ]]; then
1315
exit 1
1416
fi
1517

16-
# 2. Legacy anon and service_role key are accepted as `apikey` header
18+
# 2. Delete user with secret key
19+
user_id=$(echo "$output" | jq -r '.user.id')
20+
output=$(curl -X DELETE "http://127.0.0.1:54321/auth/v1/admin/users/$user_id" \
21+
-H "apikey: sb_secret_N7UND0UgjKTVK-Uodkm0Hg_xSvEMPvz" \
22+
-H 'Content-Type: application/json' \
23+
)
24+
if [[ "$output" != '{}' ]]; then
25+
echo 'User deletion with secret key should succeed.' >&2
26+
echo "$output" | jq
27+
exit 1
28+
fi
29+
30+
# 3. Create user with legacy anon key
1731
output=$(curl 'http://127.0.0.1:54321/auth/v1/signup' \
18-
-H 'apikey: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0' \
32+
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0' \
1933
-H 'Content-Type: application/json' \
2034
-d '{"email":"user@example.com","password":"aSecurePassword123"}' \
2135
)
@@ -24,3 +38,15 @@ if [[ $(echo "$output" | jq -r '.user.role') != 'authenticated' ]]; then
2438
echo "$output" | jq
2539
exit 1
2640
fi
41+
42+
# 4. Delete user with legacy service role key
43+
user_id=$(echo "$output" | jq -r '.user.id')
44+
output=$(curl -X DELETE "http://127.0.0.1:54321/auth/v1/admin/users/$user_id" \
45+
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU" \
46+
-H 'Content-Type: application/json' \
47+
)
48+
if [[ "$output" != '{}' ]]; then
49+
echo 'User deletion with legacy key should succeed.' >&2
50+
echo "$output" | jq
51+
exit 1
52+
fi

‎tests/edge-runtime.sh‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#!/bin/bash
22
set -eou pipefail
33

4+
# 0. Serve Edge Functions
5+
# supabase --workdir tests functions serve
6+
7+
echo "Running Edge Function tests..."
8+
49
# 1. POST request with publishable key
510
output=$(curl 'http://127.0.0.1:54321/functions/v1/hello-world' \
611
-H 'apikey: sb_publishable_ACJWlzQHlZjBrEguHvfOxg_3BJgxAaH' \

‎tests/postgrest.sh‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ set -eou pipefail
44
# 0. Create test table with RLS
55
# supabase --workdir tests migrations up
66

7+
echo "Running PostgREST tests..."
8+
79
# 1. Create todo as service role
810
output=$(curl 'http://127.0.0.1:54321/rest/v1/todos' \
911
-H 'apikey: sb_secret_N7UND0UgjKTVK-Uodkm0Hg_xSvEMPvz' \
1012
-H 'Content-Type: application/json' \
1113
-H 'Prefer: return=representation' \
12-
-d '{"task": "New task", "done": false}'
14+
-d '{"task": "New task", "done": false}' \
1315
)
1416
if [[ $(echo "$output" | jq -r 'length') != '1' ]]; then
1517
echo 'Creating todo as service role should succeed.' >&2
@@ -21,7 +23,7 @@ fi
2123
output=$(curl 'http://127.0.0.1:54321/rest/v1/todos' \
2224
-H 'apikey: sb_publishable_ACJWlzQHlZjBrEguHvfOxg_3BJgxAaH' \
2325
-H 'Content-Type: application/json' \
24-
-d '{"task": "New task", "done": false}'
26+
-d '{"task": "New task", "done": false}' \
2527
)
2628
if [[ $(echo "$output" | jq -r '.code') != '42501' ]]; then
2729
echo 'Creating todo as anon role should fail.' >&2
@@ -46,16 +48,16 @@ output=$(curl -X DELETE 'http://127.0.0.1:54321/rest/v1/todos?id=eq.1' \
4648
-H 'Content-Type: application/json' \
4749
-H 'Prefer: return=representation' \
4850
)
49-
if [[ $(echo "$output" | jq -r 'length') != '1' ]]; then
51+
if [[ $(echo "$output" | jq -r 'length') != '0' ]]; then
5052
echo 'Deleting todo as anon role should fail.' >&2
5153
echo "$output" | jq
5254
exit 1
5355
fi
5456

5557
# 5. Delete todo as authenticated role (custom jwt)
56-
output=$(curl -X DELETE 'http://127.0.0.1:54321/rest/v1/todos?id=eq.1' \
58+
output=$(curl -X DELETE 'http://127.0.0.1:54321/rest/v1/todos?id=not.eq.0' \
5759
-H 'apikey: sb_publishable_ACJWlzQHlZjBrEguHvfOxg_3BJgxAaH' \
58-
-H 'Authorization: Bearer eyJhbGciOiJFUzI1NiIsImtpZCI6ImI4MTI2OWYxLTIxZDgtNGYyZS1iNzE5LWMyMjQwYTg0MGQ5MCIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzAyNjE4NTcsImlhdCI6MTc3MDI2MDA1NywiaXNfYW5vbnltb3VzIjp0cnVlLCJyb2xlIjoiYXV0aGVudGljYXRlZCJ9.iYBqhBe9frFxmuatOzX5EtkX4h0-dFcC_d8dGeZImRA_LdVV1_fyP0MUJYm9ttR2ipL2zQ7WrjR7dbU2kBb9YQ' \
60+
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU" \
5961
-H 'Content-Type: application/json' \
6062
-H 'Prefer: return=representation' \
6163
)

‎tests/realtime.sh‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash
22
set -eou pipefail
33

4+
echo "Running Realtime tests..."
5+
46
# 1. Join realtime with legacy key
57
output=$(echo '{"topic":"realtime:room1","ref":1,"event":"phx_join","payload":{"config":{"broadcast":{"ack":true},"presence":{"enabled":true},"private":false}}}' |\
68
websocat 'ws://127.0.0.1:54321/realtime/v1/websocket?apikey=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0&vsn=1.0.0' \

‎tests/storage.sh‎

Lines changed: 2 additions & 0 deletions

0 commit comments

Comments
 (0)