-
Notifications
You must be signed in to change notification settings - Fork 4
/
wallet_test.clj
96 lines (86 loc) · 4.97 KB
/
wallet_test.clj
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
(ns integration.microservice-boilerplate.wallet-test
(:require [clojure.test :as clojure.test]
[com.stuartsierra.component :as component]
[integration.microservice-boilerplate.util :as util]
[matcher-combinators.matchers :as matchers]
[microservice-boilerplate.routes :as routes]
[parenthesin.components.config.aero :as components.config]
[parenthesin.components.db.jdbc-hikari :as components.database]
[parenthesin.components.http.clj-http :as components.http]
[parenthesin.components.router.reitit-schema :as components.router]
[parenthesin.components.server.reitit-pedestal-jetty :as components.webserver]
[parenthesin.helpers.state-flow.http :as state-flow.http]
[parenthesin.helpers.state-flow.server.pedestal :as state-flow.server]
[schema.test :as schema.test]
[state-flow.api :refer [defflow]]
[state-flow.assertions.matcher-combinators :refer [match?]]
[state-flow.core :as state-flow :refer [flow]]))
(clojure.test/use-fixtures :once schema.test/validate-schemas)
(defn- create-and-start-components! []
(component/start-system
(component/system-map
:config (components.config/new-config)
:http (components.http/new-http-mock {})
:router (components.router/new-router routes/routes)
:database (component/using (components.database/new-database)
[:config])
:webserver (component/using (components.webserver/new-webserver)
[:config :http :router :database]))))
(defflow
flow-integration-wallet-test
{:init (util/start-system! create-and-start-components!)
:cleanup util/stop-system!
:fail-fast? true}
(flow "should interact with system"
(flow "prepare system with http-out mocks"
(state-flow.http/set-http-out-responses! {"https://api.coindesk.com/v1/bpi/currentprice.json"
{:body {:bpi {:USD {:rate_float 30000.00}}}
:status 200}})
(flow "should insert deposit into wallet"
(match? (matchers/embeds {:status 201
:body {:id string?
:btc-amount 2
:usd-amount-at 60000.0}})
(state-flow.server/request! {:method :post
:uri "/wallet/deposit"
:body {:btc 2M}})))
(flow "should insert withdrawal into wallet"
(match? (matchers/embeds {:status 201
:body {:id string?
:btc-amount -1
:usd-amount-at -30000.0}})
(state-flow.server/request! {:method :post
:uri "/wallet/withdrawal"
:body {:btc -1M}})))
(flow "shouldn't insert deposit negative values into wallet"
(match? {:status 400
:body "btc deposit amount can't be negative."}
(state-flow.server/request! {:method :post
:uri "/wallet/deposit"
:body {:btc -2M}})))
(flow "shouldn't insert withdrawal positive values into wallet"
(match? {:status 400
:body "btc withdrawal amount can't be positive."}
(state-flow.server/request! {:method :post
:uri "/wallet/withdrawal"
:body {:btc 2M}})))
(flow "shouldn't insert withdrawal into wallet"
(match? {:status 400
:body "withdrawal amount bigger than the total in the wallet."}
(state-flow.server/request! {:method :post
:uri "/wallet/withdrawal"
:body {:btc -2M}})))
(flow "should list wallet deposits"
(match? (matchers/embeds {:status 200
:body {:entries [{:id string?
:btc-amount 2
:usd-amount-at 60000.0
:created-at string?}
{:id string?
:btc-amount -1
:usd-amount-at -30000.0
:created-at string?}]
:total-btc 1
:total-current-usd 30000.0}})
(state-flow.server/request! {:method :get
:uri "/wallet/history"}))))))