added tests
This commit is contained in:
@ -107,48 +107,56 @@ describe Lti do
|
|||||||
let(:consumer) { FactoryGirl.create(:consumer) }
|
let(:consumer) { FactoryGirl.create(:consumer) }
|
||||||
let(:score) { 0.5 }
|
let(:score) { 0.5 }
|
||||||
|
|
||||||
context 'with a tool provider' do
|
context 'with an invalid score' do
|
||||||
before(:each) do
|
it 'raises an exception' do
|
||||||
controller.session[:consumer_id] = consumer.id
|
expect { controller.send(:send_score, Lti::MAXIMUM_SCORE * 2) }.to raise_error(Lti::Error)
|
||||||
controller.session[:lti_parameters] = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when grading is not supported' do
|
|
||||||
it 'returns a corresponding status' do
|
|
||||||
expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:outcome_service?).and_return(false)
|
|
||||||
expect(controller.send(:send_score, score)[:status]).to eq('unsupported')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when grading is supported' do
|
|
||||||
let(:response) { double }
|
|
||||||
|
|
||||||
before(:each) do
|
|
||||||
expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:outcome_service?).and_return(true)
|
|
||||||
expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:post_replace_result!).with(score).and_return(response)
|
|
||||||
expect(response).to receive(:response_code).at_least(:once).and_return(200)
|
|
||||||
expect(response).to receive(:post_response).and_return(response)
|
|
||||||
expect(response).to receive(:body).at_least(:once).and_return('')
|
|
||||||
expect(response).to receive(:code_major).at_least(:once).and_return('success')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'sends the score' do
|
|
||||||
controller.send(:send_score, score)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns code, message, and status' do
|
|
||||||
result = controller.send(:send_score, score)
|
|
||||||
expect(result[:code]).to eq(response.response_code)
|
|
||||||
expect(result[:message]).to eq(response.body)
|
|
||||||
expect(result[:status]).to eq(response.code_major)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'without a tool provider' do
|
context 'with an valid score' do
|
||||||
it 'returns a corresponding status' do
|
context 'with a tool provider' do
|
||||||
expect(controller).to receive(:build_tool_provider).and_return(nil)
|
before(:each) do
|
||||||
expect(controller.send(:send_score, score)[:status]).to eq('error')
|
controller.session[:consumer_id] = consumer.id
|
||||||
|
controller.session[:lti_parameters] = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when grading is not supported' do
|
||||||
|
it 'returns a corresponding status' do
|
||||||
|
expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:outcome_service?).and_return(false)
|
||||||
|
expect(controller.send(:send_score, score)[:status]).to eq('unsupported')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when grading is supported' do
|
||||||
|
let(:response) { double }
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:outcome_service?).and_return(true)
|
||||||
|
expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:post_replace_result!).with(score).and_return(response)
|
||||||
|
expect(response).to receive(:response_code).at_least(:once).and_return(200)
|
||||||
|
expect(response).to receive(:post_response).and_return(response)
|
||||||
|
expect(response).to receive(:body).at_least(:once).and_return('')
|
||||||
|
expect(response).to receive(:code_major).at_least(:once).and_return('success')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'sends the score' do
|
||||||
|
controller.send(:send_score, score)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns code, message, and status' do
|
||||||
|
result = controller.send(:send_score, score)
|
||||||
|
expect(result[:code]).to eq(response.response_code)
|
||||||
|
expect(result[:message]).to eq(response.body)
|
||||||
|
expect(result[:status]).to eq(response.code_major)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'without a tool provider' do
|
||||||
|
it 'returns a corresponding status' do
|
||||||
|
expect(controller).to receive(:build_tool_provider).and_return(nil)
|
||||||
|
expect(controller.send(:send_score, score)[:status]).to eq('error')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user