AtlatestRepositorysigil-discourse

sigil-discourse / tree / testtest-client.sgl

1(import (sigil test)
2 (sigil dict)
3 (discourse client))
4
5;; ============================================================
6;; discourse-auth-headers
7;; ============================================================
8
9(test-group "discourse-auth-headers"
10 (test "returns dict with Api-Key and Api-Username"
11 (let ((headers (discourse-auth-headers "my-key" "admin")))
12 (assert-equal "my-key" (dict-ref headers Api-Key:))
13 (assert-equal "admin" (dict-ref headers Api-Username:))))
15 (test "handles empty strings"
16 (let ((headers (discourse-auth-headers "" "")))
17 (assert-equal "" (dict-ref headers Api-Key:))
18 (assert-equal "" (dict-ref headers Api-Username:)))))
20;; ============================================================
21;; discourse-url
22;; ============================================================
24(test-group "discourse-url"
25 (test "joins base URL with single path segment"
26 (assert-equal "https://forum.example.com/latest.json"
27 (discourse-url "https://forum.example.com" "latest.json")))
29 (test "joins base URL with multiple path segments"
30 (assert-equal "https://forum.example.com/t/123.json"
31 (discourse-url "https://forum.example.com" "t" "123.json")))
33 (test "does not add /api/v1 prefix"
34 (assert-equal "https://forum.example.com/categories.json"
35 (discourse-url "https://forum.example.com" "categories.json")))
37 (test "handles deeply nested paths"
38 (assert-equal "https://forum.example.com/admin/users/list/active.json"
39 (discourse-url "https://forum.example.com"
40 "admin" "users" "list" "active.json")))
42 (test "handles no path segments"
43 (assert-equal "https://forum.example.com"
44 (discourse-url "https://forum.example.com")))
46 (test "handles base URL with trailing slash"
47 (assert-equal "https://forum.example.com//latest.json"
48 (discourse-url "https://forum.example.com/" "latest.json"))))