cljs / test / ird / live / integration_test.cljs
387 words
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
(ns ird.live.integration-test
  "Live tests against https://api.ird.ro, compiled only by the :live build
  (`npm run test:live`). Only read-only GET endpoints are exercised —
  nothing here mutates the account or charges credits beyond metered reads.
  The authenticated tests skip themselves when IRD_API_KEY is not set (env
  or a local .env file)."
  (:require [cljs.test :refer [is]]
            [cljs.core.async :refer [<!]]
            [ird.client :as ird]
            [ird.credits :as credits]
            [ird.dns :as dns]
            [ird.domains :as domains]
            [ird.errors :as err]
            [ird.ipfs :as ipfs]
            [ird.p2p :as p2p]
            [ird.sharing :as sharing]
            [ird.test-util :as tu :refer [deftest-async]]))

(deftest-async anonymous-domain-check
  {:timeout-ms 30000}
  (let [resp (<! (domains/check (ird/make-client {}) "example.ro"))]
    (is (not (tu/error? resp)) (some-> resp ex-message))
    (is (= "example.ro" (:domain resp)))
    (is (string? (:status resp)))
    (is (= 200 (:ird/status (meta resp))))))

(deftest-async authenticated-read-endpoints
  {:timeout-ms 120000}
  (if-let [key (tu/api-key)]
    (let [client (ird/make-client {:api-key key :timeout-ms 30000})]
      (is (map? (<! (credits/balance client))) "credits balance")
      (is (map? (<! (credits/prices client))) "credits prices")
      (is (= "registered" (:status (<! (domains/check client "ird.ro")))) "domain check with key")
      (is (map? (<! (ird.vps/list-tiers client))) "vps tiers")
      (is (map? (<! (ipfs/usage client))) "ipfs usage")
      ;; the new DNS endpoints
      (let [claims (<! (dns/list-claims client))]
        (is (vector? (:claims claims)) "claims listing"))
      ;; gateway domains carry their served-pin count
      (let [gw-domains (:domains (<! (ipfs/list-domains client)))]
        (is (vector? gw-domains))
        (doseq [d gw-domains]
          (is (integer? (:pin_count d)) (:domain d)))
        (if-let [d (first gw-domains)]
          (let [page (<! (ipfs/list-domain-pins client (:id d) {:limit 1}))
                all (<! (ipfs/list-all-domain-pins client (:id d)))
                missing (<! (ipfs/list-domain-pins client "00000000-0000-0000-0000-000000000000"))]
            (is (integer? (:total page)))
            (is (sequential? (:pins page)))
            (is (= (:total page) (count all)) "offset pagination collects every served pin")
            (is (err/api-error? missing) "an unknown gateway domain is a 404, not a silent empty page")
            (is (= 404 (:status (ex-data missing)))))
          (println "no gateway domains on this account - skipping the pins page")))
      ;; p2p apps report their mailbox state
      (doseq [app (:apps (<! (p2p/list-apps client)))]
        (is (boolean? (:mailbox_enabled app)) (:name app))
        (is (boolean? (:mailbox_open_mint app)) (:name app))
        (is (or (nil? (:mailbox_url app)) (string? (:mailbox_url app)))))
      (let [usage (:usage (<! (p2p/usage client)))]
        (is (integer? (:cached_bytes usage)))
        (is (integer? (:mailbox_bytes_total usage)))
        ;; prices are decimal STRINGS across the API, never JSON numbers
        (is (string? (:per_mb_hour_cached usage))))
      ;; error envelope maps to :ird/api-error (JWT-only endpoint with an API key)
      (let [e (<! (sharing/list-grants client))]
        (is (err/api-error? e))
        (is (= 401 (:status (ex-data e))))))
    (println "IRD_API_KEY not set - skipping authenticated integration tests")))

static mirror of HEAD · about · clone: git clone https://ird.cod-sursa.ro/cljs.git