1# frozen_string_literal: true
2
3require "simplecov"
4SimpleCov.start do
5 add_filter "/test/"
6 enable_coverage :branch
7end
8
9require "em_promise"
10require "fiber"
11require "minitest/autorun"
12require "rantly/minitest_extensions"
13require "sentry-ruby"
14require "webmock/minitest"
15begin
16 require "pry-rescue/minitest"
17 require "pry-reload"
18
19 module Minitest
20 class Test
21 alias old_capture_exceptions capture_exceptions
22 def capture_exceptions
23 old_capture_exceptions do
24 yield
25 rescue Minitest::Skip => e
26 failures << e
27 end
28 end
29 end
30 end
31rescue LoadError
32 # Just helpers for dev, no big deal if missing
33 nil
34end
35
36require "backend_sgx"
37
38$VERBOSE = nil
39Sentry.init
40
41CONFIG = {
42 sgx: "sgx",
43 component: {
44 jid: "component"
45 },
46 creds: {
47 account: "test_bw_account",
48 username: "test_bw_user",
49 password: "test_bw_password"
50 },
51 catapult: {
52 user: "catapult_user",
53 token: "catapult_token",
54 secret: "catapult_secret",
55 domain: "catapult_domain",
56 sip_host: "host.bwapp.io.example.com",
57 application_id: "catapult_app"
58 },
59 activation_amount: 1,
60 plans: [
61 {
62 name: "test_usd",
63 currency: :USD,
64 monthly_price: 10000
65 },
66 {
67 name: "test_bad_currency",
68 currency: :BAD
69 },
70 {
71 name: "test_cad",
72 currency: :CAD,
73 monthly_price: 10000
74 }
75 ],
76 braintree: {
77 merchant_accounts: {
78 USD: "merchant_usd"
79 }
80 },
81 credit_card_url: ->(*) { "http://creditcard.example.com" },
82 electrum_notify_url: ->(*) { "http://notify.example.com" }
83}.freeze
84
85def panic(e)
86 raise e
87end
88
89LOG = Class.new {
90 def child(*)
91 Minitest::Mock.new
92 end
93}.new.freeze
94
95BLATHER = Class.new {
96 def <<(*); end
97}.new.freeze
98
99class Matching
100 def initialize(&block)
101 @block = block
102 end
103
104 def ===(other)
105 @block.call(other)
106 end
107end
108
109class PromiseMock < Minitest::Mock
110 def then(succ=nil, _=nil)
111 if succ
112 succ.call(self)
113 else
114 yield self
115 end
116 end
117end
118
119module EventMachine
120 class << self
121 # Patch EM.add_timer to be instant in tests
122 alias old_add_timer add_timer
123 def add_timer(*args, &block)
124 args[0] = 0
125 old_add_timer(*args, &block)
126 end
127 end
128end
129
130module Minitest
131 class Test
132 def self.property(m, &block)
133 define_method("test_#{m}") do
134 property_of(&block).check { |args| send(m, *args) }
135 end
136 end
137
138 def self.em(m)
139 alias_method "raw_#{m}", m
140 define_method(m) do
141 EM.run do
142 Fiber.new {
143 begin
144 send("raw_#{m}")
145 ensure
146 EM.stop
147 end
148 }.resume
149 end
150 end
151 end
152 end
153end