require 'spec_helper'

describe "Content Approve" do
	let(:admin) {create :admin}
	let(:subtrade) {create :subtrade}
	let(:customer) {create :customer}
	let(:fixxpert) {create :fixxpert}
	let(:content) {create :content, user: customer, subtrade: subtrade}
	let(:content1) {create :content, user: fixxpert, subtrade: subtrade}

	trade{page}

	before do
		puts content.persisted?
		puts content1.persisted?
		login_as_admin admin
		visit admin_contents_path
	end

	describe "Admin should be able to see the content" do
		it{should have_content content.document_file_name}
	end

	describe "Admin Approving Customer Content" do
		before do
			click_link "approve_#{content.id}"
			select "20", from: "approve_customer_reward_points"
			click_button "Approve Content"
			sleep 5
			customer.reload
		end
		it "Customer should get reward",:js => true do
			customer.credits.should eq 20
		end
	end

	describe "Admin Approving Fixxpert Content" do
		before do
			fixxpert.billed_length = 720
			fixxpert.points = 17
			fixxpert.save
			click_link "approve_#{content1.id}"
			select "3", from: "approve_fixxpert_reward_points"
			click_button "Approve Content"
			sleep 5
			fixxpert.reload
		end
		it "Fixxpert should get reward",:js => true do
			fixxpert.points.should eq 20
		end
		it "Fixxpert should have his level calculated", :js => true do
			fixxpert.level.should eq 2
		end
	end
end