dangkhoa2016 commited on
Commit
dcb1716
·
1 Parent(s): e9d5bbe

chore: add manual curl test scripts and DB inspection

Browse files

- Add manual/curl.sh for quick endpoint smoke tests
- Add manual/inspect-queries.sql for inspecting database state

README.md CHANGED
@@ -318,8 +318,17 @@ json-api-server/
318
  │ └── seed.js # Standalone script to create & seed temp DB
319
  │ └── seed-settings-coverage.test.js # Seed-settings.js V8 coverage (4)
320
  ├── manual/
 
 
 
321
  │ ├── curl.sh # Quick curl commands
322
- │ └── inspect-queries.sql # SQL queries for database inspection
 
 
 
 
 
 
323
  ├── storage/ # SQLite database files (auto-created)
324
  ├── temp/ # Temporary files (gitignored)
325
  ├── .env # Base configuration (tried first in development — highest priority)
 
318
  │ └── seed.js # Standalone script to create & seed temp DB
319
  │ └── seed-settings-coverage.test.js # Seed-settings.js V8 coverage (4)
320
  ├── manual/
321
+ │ ├── admin.sh # Admin panel curl commands
322
+ │ ├── albums.sh # Albums endpoints
323
+ │ ├── comments.sh # Comments endpoints
324
  │ ├── curl.sh # Quick curl commands
325
+ │ ├── health.sh # Health endpoint
326
+ │ ├── inspect-queries.sql # SQL queries for database inspection
327
+ │ ├── inspect.sh # Database inspection script
328
+ │ ├── photos.sh # Photos endpoints
329
+ │ ├── posts.sh # Posts endpoints
330
+ │ ├── todos.sh # Todos endpoints
331
+ │ └── users.sh # Users endpoints
332
  ├── storage/ # SQLite database files (auto-created)
333
  ├── temp/ # Temporary files (gitignored)
334
  ├── .env # Base configuration (tried first in development — highest priority)
manual/admin.sh ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ADMIN_KEY=your-secret-admin-key
2
+ BASE_URL=http://localhost:3000
3
+
4
+ # List all settings (admin only)
5
+ curl -s "$BASE_URL/api/admin/settings" \
6
+ -H "Authorization: Bearer $ADMIN_KEY"
7
+
8
+ # Update a setting
9
+ curl -s -X PATCH "$BASE_URL/api/admin/settings/DEFAULT_PAGE_SIZE" \
10
+ -H "Authorization: Bearer $ADMIN_KEY" \
11
+ -H "Content-Type: application/json" \
12
+ -d '{"value":20}'
13
+
14
+ # Reset database (delete all data, re-seed from JSONPlaceholder)
15
+ curl -s -X POST "$BASE_URL/api/admin/reset-database" \
16
+ -H "Authorization: Bearer $ADMIN_KEY" \
17
+ -H "Content-Type: application/json" \
18
+ -d '{"confirm": true}'
manual/albums.sh ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ BASE_URL=http://localhost:3000
2
+
3
+ # List (first 5)
4
+ curl -s "$BASE_URL/api/albums?_limit=5"
5
+
6
+ # Get by id
7
+ curl -s "$BASE_URL/api/albums/1"
8
+
9
+ # Filter by userId
10
+ curl -s "$BASE_URL/api/albums?userId=1"
11
+
12
+ # Search by title
13
+ curl -s "$BASE_URL/api/albums?q=quidem"
14
+
15
+ # Paginate
16
+ curl -s "$BASE_URL/api/albums?_page=1&_limit=3"
17
+
18
+ # Sort by title desc
19
+ curl -s "$BASE_URL/api/albums?_sort=title&_order=desc"
20
+
21
+ # Create
22
+ curl -s -X POST "$BASE_URL/api/albums" \
23
+ -H "Content-Type: application/json" \
24
+ -d '{"userId":1,"title":"new album"}'
25
+
26
+ # Update (partial)
27
+ curl -s -X PATCH "$BASE_URL/api/albums/1" \
28
+ -H "Content-Type: application/json" \
29
+ -d '{"title":"updated album title"}'
30
+
31
+ # Replace (full)
32
+ curl -s -X PUT "$BASE_URL/api/albums/1" \
33
+ -H "Content-Type: application/json" \
34
+ -d '{"userId":1,"title":"quidem molestiae enim"}'
35
+
36
+ # Delete the album we just created (no photos → safe to delete)
37
+ curl -s -X DELETE "$BASE_URL/api/albums/101"
38
+
39
+ # Nested: album's photos
40
+ curl -s "$BASE_URL/api/albums/1/photos"
manual/comments.sh ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ BASE_URL=http://localhost:3000
2
+
3
+ # List (first 5)
4
+ curl -s "$BASE_URL/api/comments?_limit=5"
5
+
6
+ # Get by id
7
+ curl -s "$BASE_URL/api/comments/1"
8
+
9
+ # Filter by postId
10
+ curl -s "$BASE_URL/api/comments?postId=1"
11
+
12
+ # Search by email
13
+ curl -s "$BASE_URL/api/comments?q=Lew"
14
+
15
+ # Paginate
16
+ curl -s "$BASE_URL/api/comments?_page=1&_limit=3"
17
+
18
+ # Sort by name desc
19
+ curl -s "$BASE_URL/api/comments?_sort=name&_order=desc"
20
+
21
+ # Create
22
+ curl -s -X POST "$BASE_URL/api/comments" \
23
+ -H "Content-Type: application/json" \
24
+ -d '{"postId":1,"name":"test comment","email":"test@example.com","body":"nice post!"}'
25
+
26
+ # Update (partial)
27
+ curl -s -X PATCH "$BASE_URL/api/comments/1" \
28
+ -H "Content-Type: application/json" \
29
+ -d '{"body":"updated body"}'
30
+
31
+ # Replace (full)
32
+ curl -s -X PUT "$BASE_URL/api/comments/1" \
33
+ -H "Content-Type: application/json" \
34
+ -d '{"postId":1,"name":"id labore ex et quam laborum","email":"Eliseo@gardner.biz","body":"laudantium enim quasi est quidem magnam voluptate ipsam eos\ntempora quo necessitatibus\ndolor quam autem quasi\nreiciendis et nam sapiente accusantium"}'
35
+
36
+ # Delete
37
+ curl -s -X DELETE "$BASE_URL/api/comments/1"
manual/health.sh ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ BASE_URL=http://localhost:3000
2
+
3
+ # Health check
4
+ curl -s "$BASE_URL/health" | jq .
5
+
6
+ # API root info
7
+ curl -s "$BASE_URL/api" | jq .
8
+
9
+ # CORS preflight
10
+ curl -s -X OPTIONS "$BASE_URL/api/todos" -I
manual/inspect-queries.sql CHANGED
@@ -112,7 +112,11 @@ UNION ALL
112
  SELECT 'albums', 'userId', a.userId
113
  FROM albums a LEFT JOIN users u ON u.id = a.userId WHERE u.id IS NULL;
114
 
115
- -- 8. STATISTICS
 
 
 
 
116
  -- ..............................................................................
117
  SELECT 'posts' AS type, AVG(LENGTH(body)) AS avg_len, MIN(LENGTH(body)) AS min_len, MAX(LENGTH(body)) AS max_len FROM posts
118
  UNION ALL
 
112
  SELECT 'albums', 'userId', a.userId
113
  FROM albums a LEFT JOIN users u ON u.id = a.userId WHERE u.id IS NULL;
114
 
115
+ -- 8. SETTINGS
116
+ -- ..............................................................................
117
+ SELECT id, key, value, description, updated_at FROM settings ORDER BY key;
118
+
119
+ -- 9. STATISTICS
120
  -- ..............................................................................
121
  SELECT 'posts' AS type, AVG(LENGTH(body)) AS avg_len, MIN(LENGTH(body)) AS min_len, MAX(LENGTH(body)) AS max_len FROM posts
122
  UNION ALL
manual/inspect.sh ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -e
3
+ DB="${1:-storage/data.db}"
4
+ DIR=$(dirname "$0")
5
+
6
+ sqlite3 -header -column "$DB" <<SQL
7
+ $(awk '
8
+ /^-- [0-9]+\./ {
9
+ gsub(/^-- /, "")
10
+ title = $0
11
+ line = title; gsub(/./, "─", line)
12
+ print ".print \"\""
13
+ print ".print \"┌─" line "─┐\""
14
+ print ".print \"│ " title " │\""
15
+ print ".print \"└─" line "─┘\""
16
+ next
17
+ }
18
+ /^-- =/ { next }
19
+ /^-- Usage/ { next }
20
+ /^-- \.\.\./ { next }
21
+ /^--$/ { next }
22
+ 1
23
+ ' "$DIR/inspect-queries.sql")
24
+ SQL
manual/photos.sh ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ BASE_URL=http://localhost:3000
2
+
3
+ # List (first 5)
4
+ curl -s "$BASE_URL/api/photos?_limit=5"
5
+
6
+ # Get by id
7
+ curl -s "$BASE_URL/api/photos/1"
8
+
9
+ # Filter by albumId
10
+ curl -s "$BASE_URL/api/photos?albumId=1"
11
+
12
+ # Search by title
13
+ curl -s "$BASE_URL/api/photos?q=accusamus"
14
+
15
+ # Paginate
16
+ curl -s "$BASE_URL/api/photos?_page=2&_limit=3"
17
+
18
+ # Sort by title desc
19
+ curl -s "$BASE_URL/api/photos?_sort=title&_order=desc"
20
+
21
+ # Create
22
+ curl -s -X POST "$BASE_URL/api/photos" \
23
+ -H "Content-Type: application/json" \
24
+ -d '{"albumId":1,"title":"new photo","url":"https://example.com/photo.jpg","thumbnailUrl":"https://example.com/thumb.jpg"}'
25
+
26
+ # Update (partial)
27
+ curl -s -X PATCH "$BASE_URL/api/photos/1" \
28
+ -H "Content-Type: application/json" \
29
+ -d '{"title":"updated photo title"}'
30
+
31
+ # Replace (full)
32
+ curl -s -X PUT "$BASE_URL/api/photos/1" \
33
+ -H "Content-Type: application/json" \
34
+ -d '{"albumId":1,"title":"accusamus beatae ad facilis cum similique qui sunt","url":"https://via.placeholder.com/600/92c952","thumbnailUrl":"https://via.placeholder.com/150/92c952"}'
35
+
36
+ # Delete
37
+ curl -s -X DELETE "$BASE_URL/api/photos/1"
manual/posts.sh ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ BASE_URL=http://localhost:3000
2
+
3
+ # List (first 5)
4
+ curl -s "$BASE_URL/api/posts?_limit=5"
5
+
6
+ # Get by id
7
+ curl -s "$BASE_URL/api/posts/1"
8
+
9
+ # Filter by userId
10
+ curl -s "$BASE_URL/api/posts?userId=1"
11
+
12
+ # Search
13
+ curl -s "$BASE_URL/api/posts?q=qui"
14
+
15
+ # Paginate
16
+ curl -s "$BASE_URL/api/posts?_page=2&_limit=3"
17
+
18
+ # Sort by title desc
19
+ curl -s "$BASE_URL/api/posts?_sort=title&_order=desc"
20
+
21
+ # Create
22
+ curl -s -X POST "$BASE_URL/api/posts" \
23
+ -H "Content-Type: application/json" \
24
+ -d '{"userId":1,"title":"new post","body":"hello world"}'
25
+
26
+ # Update (partial)
27
+ curl -s -X PATCH "$BASE_URL/api/posts/1" \
28
+ -H "Content-Type: application/json" \
29
+ -d '{"title":"updated title"}'
30
+
31
+ # Replace (full)
32
+ curl -s -X PUT "$BASE_URL/api/posts/1" \
33
+ -H "Content-Type: application/json" \
34
+ -d '{"userId":1,"title":"sunt aut facere repellat provident occaecati excepturi optio reprehenderit","body":"quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"}'
35
+
36
+ # Delete the post we just created (safe — no dependent comments)
37
+ curl -s -X DELETE "$BASE_URL/api/posts/101"
38
+
39
+ # Nested: post's comments
40
+ curl -s "$BASE_URL/api/posts/1/comments"
manual/todos.sh ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ BASE_URL=http://localhost:3000
2
+
3
+ # List (first 5)
4
+ curl -s "$BASE_URL/api/todos?_limit=5"
5
+
6
+ # Get by id
7
+ curl -s "$BASE_URL/api/todos/1"
8
+
9
+ # Filter by userId + completed
10
+ curl -s "$BASE_URL/api/todos?userId=1&completed=true"
11
+
12
+ # Search by title
13
+ curl -s "$BASE_URL/api/todos?q=delectus"
14
+
15
+ # Paginate: page 2, limit 3
16
+ curl -s "$BASE_URL/api/todos?_page=2&_limit=3"
17
+
18
+ # Sort by title desc
19
+ curl -s "$BASE_URL/api/todos?_sort=title&_order=desc"
20
+
21
+ # Create
22
+ curl -s -X POST "$BASE_URL/api/todos" \
23
+ -H "Content-Type: application/json" \
24
+ -d '{"userId":1,"title":"learn curl","completed":false}'
25
+
26
+ # Update (partial)
27
+ curl -s -X PATCH "$BASE_URL/api/todos/1" \
28
+ -H "Content-Type: application/json" \
29
+ -d '{"completed":true}'
30
+
31
+ # Replace (full)
32
+ curl -s -X PUT "$BASE_URL/api/todos/1" \
33
+ -H "Content-Type: application/json" \
34
+ -d '{"userId":1,"title":"delectus aut autem","completed":false}'
35
+
36
+ # Delete the todo we just created
37
+ curl -s -X DELETE "$BASE_URL/api/todos/201"
manual/users.sh ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ BASE_URL=http://localhost:3000
2
+
3
+ # List (first 5)
4
+ curl -s "$BASE_URL/api/users?_limit=5"
5
+
6
+ # Get by id
7
+ curl -s "$BASE_URL/api/users/1"
8
+
9
+ # Filter by username
10
+ curl -s "$BASE_URL/api/users?username=Bret"
11
+
12
+ # Search
13
+ curl -s "$BASE_URL/api/users?q=Leanne"
14
+
15
+ # Paginate
16
+ curl -s "$BASE_URL/api/users?_page=1&_limit=3"
17
+
18
+ # Sort by name desc
19
+ curl -s "$BASE_URL/api/users?_sort=name&_order=desc"
20
+
21
+ # Create
22
+ curl -s -X POST "$BASE_URL/api/users" \
23
+ -H "Content-Type: application/json" \
24
+ -d '{"name":"Test User","username":"testuser","email":"test@example.com"}'
25
+
26
+ # Update (partial)
27
+ curl -s -X PATCH "$BASE_URL/api/users/1" \
28
+ -H "Content-Type: application/json" \
29
+ -d '{"email":"new@example.com"}'
30
+
31
+ # Replace (full)
32
+ curl -s -X PUT "$BASE_URL/api/users/1" \
33
+ -H "Content-Type: application/json" \
34
+ -d '{"name":"Leanne Graham","username":"Bret","email":"Sincere@april.biz","phone":"1-770-736-8031 x56442","website":"hildegard.org"}'
35
+
36
+ # Delete
37
+ curl -s -X DELETE "$BASE_URL/api/users/1"
38
+
39
+ # Nested: user's posts
40
+ curl -s "$BASE_URL/api/users/1/posts"
41
+
42
+ # Nested: user's albums
43
+ curl -s "$BASE_URL/api/users/1/albums"
44
+
45
+ # Nested: user's todos
46
+ curl -s "$BASE_URL/api/users/1/todos"