|
| 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(:candlesticks) { client.polymarket.candlesticks } |
| 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 Candlesticks' do |
| 16 | + it 'gets candlesticks with interval' do |
| 17 | + stub_request(:get, 'https://api.domeapi.io/v1/polymarket/markets/get_candlesticks') |
| 18 | + .with(query: { condition_id: 'abc', start_time: '100', end_time: '200', interval: '60' }) |
| 19 | + .to_return(status: 200, body: '{"candlesticks": []}') |
| 20 | + |
| 21 | + filter = Rubyists::Domeapi::Polymarket::Candlesticks::Filter.new( |
| 22 | + Rubyists::Domeapi::Polymarket::Candlesticks::Filter::Properties.new( |
| 23 | + condition_id: 'abc', |
| 24 | + start_time: 100, |
| 25 | + end_time: 200, |
| 26 | + interval: 60 |
| 27 | + ) |
| 28 | + ) |
| 29 | + response = candlesticks.get(filter) |
| 30 | + |
| 31 | + _(response).must_equal({ candlesticks: [] }) |
| 32 | + end |
| 33 | + |
| 34 | + it 'gets candlesticks without interval' do |
| 35 | + stub_request(:get, 'https://api.domeapi.io/v1/polymarket/markets/get_candlesticks') |
| 36 | + .with(query: { condition_id: 'abc', start_time: '100', end_time: '200' }) |
| 37 | + .to_return(status: 200, body: '{"candlesticks": []}') |
| 38 | + |
| 39 | + filter = Rubyists::Domeapi::Polymarket::Candlesticks::Filter.new( |
| 40 | + Rubyists::Domeapi::Polymarket::Candlesticks::Filter::Properties.new( |
| 41 | + condition_id: 'abc', |
| 42 | + start_time: 100, |
| 43 | + end_time: 200 |
| 44 | + ) |
| 45 | + ) |
| 46 | + response = candlesticks.get(filter) |
| 47 | + |
| 48 | + _(response).must_equal({ candlesticks: [] }) |
| 49 | + end |
| 50 | + |
| 51 | + it 'validates required parameters' do |
| 52 | + filter = Rubyists::Domeapi::Polymarket::Candlesticks::Filter.new( |
| 53 | + Rubyists::Domeapi::Polymarket::Candlesticks::Filter::Properties.new |
| 54 | + ) |
| 55 | + |
| 56 | + error = _ { candlesticks.get(filter) }.must_raise ArgumentError |
| 57 | + _(error.message).must_include 'Condition Id must be filled' |
| 58 | + _(error.message).must_include 'Start Time must be filled' |
| 59 | + _(error.message).must_include 'End Time must be filled' |
| 60 | + end |
| 61 | + |
| 62 | + it 'validates interval range' do |
| 63 | + filter = Rubyists::Domeapi::Polymarket::Candlesticks::Filter.new( |
| 64 | + Rubyists::Domeapi::Polymarket::Candlesticks::Filter::Properties.new( |
| 65 | + condition_id: 'abc', |
| 66 | + start_time: 100, |
| 67 | + end_time: 200, |
| 68 | + interval: 1441 |
| 69 | + ) |
| 70 | + ) |
| 71 | + |
| 72 | + error = _ { candlesticks.get(filter) }.must_raise ArgumentError |
| 73 | + _(error.message).must_include 'Interval must be less than or equal to 1440' |
| 74 | + |
| 75 | + filter = Rubyists::Domeapi::Polymarket::Candlesticks::Filter.new( |
| 76 | + Rubyists::Domeapi::Polymarket::Candlesticks::Filter::Properties.new( |
| 77 | + condition_id: 'abc', |
| 78 | + start_time: 100, |
| 79 | + end_time: 200, |
| 80 | + interval: 0 |
| 81 | + ) |
| 82 | + ) |
| 83 | + |
| 84 | + error = _ { candlesticks.get(filter) }.must_raise ArgumentError |
| 85 | + _(error.message).must_include 'Interval must be greater than or equal to 1' |
| 86 | + end |
| 87 | + end |
| 88 | +end |
0 commit comments