|
29 | 29 |
|
30 | 30 | (deftest snapshot-download-uses-gzip-encoding-when-compression-supported-test |
31 | 31 | (async done |
32 | | - (let [put-call (atom nil) |
33 | | - rows [[1 "row-1" nil] |
34 | | - [2 "row-2" "{\"a\":1}"]] |
35 | | - bucket #js {:put (fn [key body opts] |
36 | | - (reset! put-call {:key key :body body :opts opts}) |
37 | | - (js/Promise.resolve #js {:ok true}))} |
38 | | - sql (empty-sql) |
| 32 | + (let [sql (empty-sql) |
39 | 33 | conn (d/create-conn db-schema/schema) |
40 | | - self #js {:env #js {:LOGSEQ_SYNC_ASSETS bucket} |
| 34 | + self #js {:env #js {} |
41 | 35 | :conn conn |
42 | 36 | :schema-ready true |
43 | 37 | :sql sql} |
44 | 38 | {:keys [request url]} (request-url) |
45 | | - original-compression-stream (.-CompressionStream js/globalThis) |
46 | | - restore! #(aset js/globalThis "CompressionStream" original-compression-stream)] |
47 | | - (aset js/globalThis |
48 | | - "CompressionStream" |
49 | | - (passthrough-compression-stream-constructor)) |
50 | | - (-> (p/with-redefs [sync-handler/fetch-snapshot-kvs-rows (fn [_sql last-addr _limit] |
51 | | - (if (neg? last-addr) rows [])) |
52 | | - sync-handler/snapshot-row-count (fn [_sql] (count rows))] |
53 | | - (p/let [resp (sync-handler/handle {:self self |
54 | | - :request request |
55 | | - :url url |
56 | | - :route {:handler :sync/snapshot-download}}) |
| 39 | + expected-url "http://localhost/sync/graph-1/snapshot/stream"] |
| 40 | + (-> (p/let [resp (sync-handler/handle {:self self |
| 41 | + :request request |
| 42 | + :url url |
| 43 | + :route {:handler :sync/snapshot-download}}) |
57 | 44 | text (.text resp) |
58 | | - body (js->clj (js/JSON.parse text) :keywordize-keys true) |
59 | | - http-metadata (aget (:opts @put-call) "httpMetadata") |
60 | | - payload (js/Uint8Array. (:body @put-call)) |
61 | | - rows (snapshot/finalize-framed-buffer payload) |
62 | | - addrs (mapv first rows)] |
| 45 | + body (js->clj (js/JSON.parse text) :keywordize-keys true)] |
63 | 46 | (is (= 200 (.-status resp))) |
| 47 | + (is (= true (:ok body))) |
| 48 | + (is (= "stream/graph-1.snapshot" (:key body))) |
| 49 | + (is (= expected-url (:url body))) |
64 | 50 | (is (= "gzip" (:content-encoding body))) |
65 | | - (is (= "gzip" (aget http-metadata "contentEncoding"))) |
66 | | - (is (= "application/transit+json" (aget http-metadata "contentType"))) |
67 | | - (is (= 2 (count rows))) |
68 | | - (is (= (sort addrs) addrs)) |
69 | | - (is (every? (fn [[addr content _addresses]] |
70 | | - (and (int? addr) |
71 | | - (string? content))) |
72 | | - rows)) |
73 | | - (is (= [[1 "row-1" nil] |
74 | | - [2 "row-2" "{\"a\":1}"]] |
75 | | - rows)))) |
| 51 | + (done)) |
76 | 52 | (p/then (fn [] |
77 | | - (restore!) |
78 | | - (done))) |
| 53 | + nil)) |
79 | 54 | (p/catch (fn [error] |
80 | | - (restore!) |
81 | 55 | (is false (str error)) |
82 | 56 | (done))))))) |
83 | 57 |
|
|
0 commit comments