require_relative('spec_helper.rb')

describe StackifyClassificator::Mechanize, 'Mechanize' do

	before(:each) do
		stack_api = Stackify::QuestionOffline.new(:key=>'')

    global_stop_tags = JSON.parse File.read('spec/fixtures/global_stop_tags.json')
    global_stop_tags_include = JSON.parse File.read('spec/fixtures/global_stop_tags_include.json')
    rules = JSON.parse File.read('spec/fixtures/rules.json')
	metagroups = JSON.parse File.read('spec/fixtures/metagroups.json')
    skipped_groups = JSON.parse File.read('spec/fixtures/skipped_groups.json')
	priority_groups = JSON.parse File.read('spec/fixtures/priority_groups.json')

    @settings = StackifyClassificator::Settings.new(:global_stop_tags => global_stop_tags,
                                                    :global_stop_tags_include => global_stop_tags_include,
                                                    :rules => rules,
													:metagroups => metagroups,
                                                    :skipped_groups => skipped_groups,
													:priority_groups => priority_groups)

    @classificator = StackifyClassificator::Classifier.new(@settings)
    @spam_filter = StackifyClassificator::SpamFilter.new(@settings)

    @mechanize = StackifyClassificator::Mechanize.new(:stackapi => stack_api,
                                                      :classifier => @classificator,
                                                      :filter => @spam_filter)
	end

	it 'it should return data structure for questions' do
		result = @mechanize.get_new_questions
		quota_remaining = @mechanize.quota_remaining
		number_of_queries = @mechanize.number_of_queries

		expect(result.count).to eq(23)
		expect(result['objective-c'].count).to eq(6)
		expect(result['git'].count).to eq(1)
		expect(result['objective-c'][0]['score']).to eq(0)
		expect(result['objective-c'][0]['last_activity_date']).to eq(1409992163)
		expect(result['objective-c'][0]['title']).to eq('How do I add spaces after a string')
		expect(result['objective-c'][0]['metagroup']).to eq('ios')

		expect(quota_remaining).to eq(100)
		expect(number_of_queries).to eq(2)
	end

end
