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}.freeze
79
80BLATHER = Class.new {
81 def <<(*); end
82}.new.freeze
83
84class Matching
85 def initialize(&block)
86 @block = block
87 end
88
89 def ===(other)
90 @block.call(other)
91 end
92end
93
94class PromiseMock < Minitest::Mock
95 def then(succ=nil, _=nil)
96 if succ
97 succ.call(self)
98 else
99 yield self
100 end
101 end
102end
103
104module EventMachine
105 class << self
106 # Patch EM.add_timer to be instant in tests
107 alias old_add_timer add_timer
108 def add_timer(*args, &block)
109 args[0] = 0
110 old_add_timer(*args, &block)
111 end
112 end
113end
114
115module Minitest
116 class Test
117 def self.property(m, &block)
118 define_method("test_#{m}") do
119 property_of(&block).check { |args| send(m, *args) }
120 end
121 end
122
123 def self.em(m)
124 alias_method "raw_#{m}", m
125 define_method(m) do
126 EM.run do
127 Fiber.new {
128 begin
129 send("raw_#{m}")
130 ensure
131 EM.stop
132 end
133 }.resume
134 end
135 end
136 end
137 end
138end