bitget.rb 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,5 +2,5 @@
2
2
  # Bitget::VERSION
3
3
 
4
4
  module Bitget
5
- VERSION = '0.4.0'
5
+ VERSION = '0.5.0'
6
6
  end
@@ -0,0 +1,92 @@
1
+ require_relative '../helper'
2
+ require_relative '../../lib/Bitget/V2/Client'
3
+
4
+ describe Bitget::V2::Client do
5
+ let(:api_key){ENV.fetch('BITGET_API_KEY', '<API_KEY>')}
6
+ let(:api_secret){ENV.fetch('BITGET_API_SECRET', '<API_SECRET>')}
7
+ let(:api_passphrase){ENV.fetch('BITGET_API_PASSPHRASE', '<API_PASSPHRASE>')}
8
+
9
+ let(:client) do
10
+ Bitget::V2::Client.new(
11
+ api_key: api_key,
12
+ api_secret: api_secret,
13
+ api_passphrase: api_passphrase
14
+ )
15
+ end
16
+
17
+ describe "logging" do
18
+ before do
19
+ FileUtils.rm_f(client.class.log_file_path)
20
+ client.class.instance_variable_set(:@log_file_path, nil)
21
+ client.class.instance_variable_set(:@logger, nil)
22
+ end
23
+
24
+ after do
25
+ FileUtils.rm_f(client.class.log_file_path)
26
+ end
27
+
28
+ describe "logging configuration" do
29
+ it "uses the configured log file path" do
30
+ client.class.log_file_path = '/some/path'
31
+ _(client.class.log_file_path).must_equal(File.expand_path('/some/path'))
32
+ end
33
+
34
+ it "creates log directory if it doesn't exist" do
35
+ nested_path = File.join(Dir.tmpdir, 'bitget_test', 'nested', 'test.log')
36
+ client.class.log_file_path = nested_path
37
+ client.class.logger
38
+ _(File.directory?(File.dirname(nested_path))).must_equal(true)
39
+ end
40
+
41
+ it "creates a daily rotating logger" do
42
+ _(client.class.logger).must_be_kind_of(Logger)
43
+ _(File.exist?(client.class.log_file_path)).must_equal(true)
44
+ end
45
+ end
46
+
47
+ describe "request logging" do
48
+ it "logs requests" do
49
+ client.class.logger
50
+ VCR.use_cassette('v2/spot/public/coins-when_coin_is_supplied') do
51
+ client.spot_public_coins(coin: 'BTC')
52
+ end
53
+ client.class.logger.close
54
+ log_content = File.read(client.class.log_file_path)
55
+ _(log_content).must_match(/GET https:\/\/api.bitget.com\/api\/v2\/spot\/public\/coins/)
56
+ _(log_content).must_match(/Args: \{coin: \"BTC\"}/)
57
+ _(log_content).must_match(/Headers: .+\"Content-Type\" => \"application\/json\"/)
58
+ end
59
+ end
60
+
61
+ describe "response logging" do
62
+ it "logs responses" do
63
+ client.class.logger
64
+ VCR.use_cassette('v2/spot/public/coins-when_coin_is_supplied') do
65
+ client.spot_public_coins(coin: 'BTC')
66
+ end
67
+ client.class.logger.close
68
+ log_content = File.read(client.class.log_file_path)
69
+ _(log_content).must_match(/Code:/)
70
+ _(log_content).must_match(/Message:/)
71
+ _(log_content).must_match(/Body:/)
72
+ end
73
+ end
74
+
75
+ describe "error logging" do
76
+ it "logs error responses" do
77
+ client.class.logger
78
+ VCR.use_cassette('v2/spot/public/coins-when_error_occurs') do
79
+ begin
80
+ client.spot_public_coins(coin: 'INVALID')
81
+ rescue Bitget::Error
82
+ end
83
+ end
84
+ client.class.logger.close
85
+ log_content = File.read(client.class.log_file_path)
86
+ _(log_content).must_match(/Code:/)
87
+ _(log_content).must_match(/Message:/)
88
+ _(log_content).must_match(/Body:/)
89
+ end
90
+ end
91
+ end
92
+ end