|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require_relative '../../helper' |
| 4 | + |
| 5 | +describe Rubyists::Domeapi::Client do |
| 6 | + let(:client) { Rubyists::Domeapi::Client.new } |
| 7 | + let(:trade_history) { client.polymarket.trade_history } |
| 8 | + |
| 9 | + before do |
| 10 | + Rubyists::Domeapi.configure do |config| |
| 11 | + config.api_key = 'test_api_key' |
| 12 | + end |
| 13 | + end |
| 14 | + |
| 15 | + describe 'Polymarket Trade History' do |
| 16 | + it 'gets trade history' do |
| 17 | + stub_request(:get, 'https://api.domeapi.io/v1/polymarket/markets/get_trade_history') |
| 18 | + .with(query: { market_slug: 'slug', limit: '10' }) |
| 19 | + .to_return(status: 200, body: '{"trades": []}') |
| 20 | + |
| 21 | + filter = Rubyists::Domeapi::Polymarket::TradeHistory::Filter.new( |
| 22 | + Rubyists::Domeapi::Polymarket::TradeHistory::Filter::Properties.new( |
| 23 | + market_slug: 'slug', |
| 24 | + limit: 10 |
| 25 | + ) |
| 26 | + ) |
| 27 | + response = trade_history.list(filter) |
| 28 | + |
| 29 | + _(response).must_equal({ trades: [] }) |
| 30 | + end |
| 31 | + |
| 32 | + it 'validates limit range' do |
| 33 | + filter = Rubyists::Domeapi::Polymarket::TradeHistory::Filter.new( |
| 34 | + Rubyists::Domeapi::Polymarket::TradeHistory::Filter::Properties.new(limit: 1001) |
| 35 | + ) |
| 36 | + |
| 37 | + error = _ { trade_history.list(filter) }.must_raise ArgumentError |
| 38 | + _(error.message).must_include 'Limit must be less than or equal to 1000' |
| 39 | + |
| 40 | + filter = Rubyists::Domeapi::Polymarket::TradeHistory::Filter.new( |
| 41 | + Rubyists::Domeapi::Polymarket::TradeHistory::Filter::Properties.new(limit: 0) |
| 42 | + ) |
| 43 | + |
| 44 | + error = _ { trade_history.list(filter) }.must_raise ArgumentError |
| 45 | + _(error.message).must_include 'Limit must be greater than or equal to 1' |
| 46 | + end |
| 47 | + |
| 48 | + it 'validates offset range' do |
| 49 | + filter = Rubyists::Domeapi::Polymarket::TradeHistory::Filter.new( |
| 50 | + Rubyists::Domeapi::Polymarket::TradeHistory::Filter::Properties.new(offset: -1) |
| 51 | + ) |
| 52 | + |
| 53 | + error = _ { trade_history.list(filter) }.must_raise ArgumentError |
| 54 | + _(error.message).must_include 'Offset must be greater than or equal to 0' |
| 55 | + end |
| 56 | + end |
| 57 | +end |
0 commit comments