spec/rest/stats/subuser_spec.rb in sendgrid4r-1.8.1 vs spec/rest/stats/subuser_spec.rb in sendgrid4r-1.10.0

- old
+ new

@@ -1,40 +1,40 @@ # encoding: utf-8 require File.dirname(__FILE__) + '/../../spec_helper' -describe SendGrid4r::REST::Stats::Subuser do - describe 'integration test', :it do - before do - Dotenv.load - @client = SendGrid4r::Client.new(api_key: ENV['SILVER_API_KEY']) - @subuser = ENV['SUBUSER2'] - @email1 = ENV['MAIL'] - @password1 = ENV['PASS'] - @ip = ENV['IP'] - subusers = @client.get_subusers - count = subusers.count { |subuser| subuser.username == @subuser } - @client.post_subuser( - username: @subuser, - email: @email1, - password: @password1, - ips: [@ip] - ) if count == 0 - end +module SendGrid4r::REST::Stats + describe Subuser do + describe 'integration test', :it do + before do + Dotenv.load + @client = SendGrid4r::Client.new(api_key: ENV['SILVER_API_KEY']) + @subuser = ENV['SUBUSER2'] + @email1 = ENV['MAIL'] + @password1 = ENV['PASS'] + @ip = ENV['IP'] + subusers = @client.get_subusers + count = subusers.count { |subuser| subuser.username == @subuser } + @client.post_subuser( + username: @subuser, + email: @email1, + password: @password1, + ips: [@ip] + ) if count == 0 + end - context 'without block call' do - it '#get_subusers_stats with mandatory params' do - begin + context 'without block call' do + it '#get_subusers_stats with mandatory params' do top_stats = @client.get_subusers_stats( start_date: '2015-01-01', subusers: @subuser ) expect(top_stats).to be_a(Array) top_stats.each do |global_stat| - expect(global_stat).to be_a(SendGrid4r::REST::Stats::TopStat) + expect(global_stat).to be_a(TopStat) global_stat.stats.each do |stat| - expect(stat).to be_a(SendGrid4r::REST::Stats::Stat) - expect(stat.metrics).to be_a(SendGrid4r::REST::Stats::Metric) + expect(stat).to be_a(Stat) + expect(stat.metrics).to be_a(Metric) expect(stat.metrics.blocks.nil?).to be(false) expect(stat.metrics.bounce_drops.nil?).to be(false) expect(stat.metrics.bounces.nil?).to be(false) expect(stat.metrics.clicks.nil?).to be(false) expect(stat.metrics.deferred.nil?).to be(false) @@ -49,69 +49,109 @@ expect(stat.metrics.unique_opens.nil?).to be(false) expect(stat.metrics.unsubscribe_drops.nil?).to be(false) expect(stat.metrics.unsubscribes.nil?).to be(false) end end - rescue RestClient::ExceptionWithResponse => e - puts e.inspect - raise e end - end - it '#get_subusers_stats with all params' do - begin + it '#get_subusers_stats with all params' do top_stats = @client.get_subusers_stats( start_date: '2015-01-01', end_date: '2015-01-02', - aggregated_by: SendGrid4r::REST::Stats::AggregatedBy::WEEK, + aggregated_by: :week, subusers: @subuser ) expect(top_stats.class).to be(Array) top_stats.each do |global_stat| - expect(global_stat).to be_a(SendGrid4r::REST::Stats::TopStat) + expect(global_stat).to be_a(TopStat) global_stat.stats.each do |stat| - expect(stat).to be_a(SendGrid4r::REST::Stats::Stat) - expect(stat.metrics).to be_a(SendGrid4r::REST::Stats::Metric) + expect(stat).to be_a(Stat) + expect(stat.metrics).to be_a(Metric) end end - rescue RestClient::ExceptionWithResponse => e - puts e.inspect - raise e end - end - it '#get_subusers_stats_sums with mandatory params' do - begin + it '#get_subusers_stats_sums with mandatory params' do top_stat = @client.get_subusers_stats_sums(start_date: '2015-01-01') - expect(top_stat).to be_a(SendGrid4r::REST::Stats::TopStat) + expect(top_stat).to be_a(TopStat) top_stat.stats.each do |stat| - expect(stat).to be_a(SendGrid4r::REST::Stats::Stat) - expect(stat.metrics).to be_a(SendGrid4r::REST::Stats::Metric) + expect(stat).to be_a(Stat) + expect(stat.metrics).to be_a(Metric) end - rescue RestClient::ExceptionWithResponse => e - puts e.inspect - raise e end - end - it '#get_subusers_stats_sums with all params' do - begin + it '#get_subusers_stats_sums with all params' do top_stat = @client.get_subusers_stats_sums( start_date: '2015-01-01', end_date: '2015-01-02', - sort_by_metric: 'opens', - sort_by_direction: 'desc', + sort_by_metric: :opens, + sort_by_direction: :desc, limit: 5, offset: 0 ) - expect(top_stat).to be_a(SendGrid4r::REST::Stats::TopStat) + expect(top_stat).to be_a(TopStat) top_stat.stats.each do |stat| - expect(stat).to be_a(SendGrid4r::REST::Stats::Stat) - expect(stat.metrics).to be_a(SendGrid4r::REST::Stats::Metric) + expect(stat).to be_a(Stat) + expect(stat.metrics).to be_a(Metric) end - rescue RestClient::ExceptionWithResponse => e - puts e.inspect - raise e + end + + it '#get_subusers_stats_monthly with mandatory params' do + top_stat = @client.get_subusers_stats_monthly( + date: '2015-01-01' + ) + expect(top_stat).to be_a(TopStat) + top_stat.stats.each do |stat| + expect(stat).to be_a(Stat) + expect(stat.metrics).to be_a(Metric) + end + end + + it '#get_subusers_stats_monthly with all params' do + begin + top_stat = @client.get_subusers_stats_monthly( + date: '2015-01-01', + subuser: ENV['SUBUSER'], + sort_by_metric: :opens, + sort_by_direction: :desc, + limit: 5, + offset: 0 + ) + expect(top_stat).to be_a(TopStat) + top_stat.stats.each do |stat| + expect(stat).to be_a(Stat) + expect(stat.metrics).to be_a(Metric) + end + rescue RestClient::ExceptionWithResponse => e + puts e.inspect + raise e + end + end + + it '#get_subuser_stats_monthly with mandatory params' do + top_stat = @client.get_subuser_stats_monthly( + subuser_name: ENV['SUBUSER'], date: '2015-01-01' + ) + expect(top_stat).to be_a(TopStat) + top_stat.stats.each do |stat| + expect(stat).to be_a(Stat) + expect(stat.metrics).to be_a(Metric) + end + end + + it '#get_subuser_stats_monthly with all params' do + top_stat = @client.get_subuser_stats_monthly( + subuser_name: ENV['SUBUSER'], date: '2015-01-01', + sort_by_metric: :opens, + sort_by_direction: :desc, + limit: 5, + offset: 0 + ) + expect(top_stat).to be_a(TopStat) + top_stat.stats.each do |stat| + expect(stat).to be_a(Stat) + expect(stat.metrics).to be_a(Metric) + end end end end end end