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