Skip to content

Commit

Permalink
(test) add live feedback history tests
Browse files Browse the repository at this point in the history
  • Loading branch information
syoopie committed Aug 28, 2024
1 parent 6837a5b commit c9eb16e
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 0 deletions.
97 changes: 97 additions & 0 deletions spec/controllers/course/statistics/assessment_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,102 @@
it { expect { subject }.to raise_exception(CanCan::AccessDenied) }
end
end

describe '#live_feedback_history' do
let(:question) do
create(:course_assessment_question_programming, assessment: assessment).acting_as
end
let(:user) { create(:user) }

let!(:course_student) { create(:course_student, course: course, user: user) }
let!(:live_feedback) do
create(:course_assessment_live_feedback, assessment: assessment,
question: question,
creator: course_student)
end
let!(:code) { create(:course_assessment_live_feedback_code, feedback: live_feedback) }
let!(:comment) do
create(:course_assessment_live_feedback_comment, code: code, line_number: 1,
comment: 'This is a test comment')
end
render_views
subject do
get :live_feedback_history, as: :json,
params: {
course_id: course,
id: assessment.id,
question_id: question.id,
course_user_id: course_student.id
}
end

context 'when the Normal User wants to get live feedback history' do
before { controller_sign_in(controller, user) }

it { expect { subject }.to raise_exception(CanCan::AccessDenied) }
end

context 'when the Course Manager wants to get live feedback history' do
let(:course_manager) { create(:course_manager, course: course) }

before { controller_sign_in(controller, course_manager.user) }

it 'returns the live feedback history successfully' do
expect(subject).to have_http_status(:success)
json_result = JSON.parse(response.body)

feedback_history = json_result['liveFeedbackHistory']
question = json_result['question']

expect(feedback_history).not_to be_empty
expect(feedback_history.first).to have_key('files')

file = feedback_history.first['files'].first
expect(file).to have_key('filename')
expect(file).to have_key('content')
expect(file).to have_key('language')
expect(file).to have_key('comments')

comment = file['comments'].first
expect(comment).to have_key('lineNumber')
expect(comment).to have_key('comment')

expect(question).not_to be_empty
expect(question).to have_key('title')
expect(question).to have_key('description')
end
end

context 'when the Administrator wants to get live feedback history' do
let(:administrator) { create(:administrator) }

before { controller_sign_in(controller, administrator) }

it 'returns the live feedback history successfully' do
expect(subject).to have_http_status(:success)
json_result = JSON.parse(response.body)

feedback_history = json_result['liveFeedbackHistory']
question = json_result['question']

expect(feedback_history).not_to be_empty
expect(feedback_history.first).to have_key('files')

file = feedback_history.first['files'].first
expect(file).to have_key('filename')
expect(file).to have_key('content')
expect(file).to have_key('language')
expect(file).to have_key('comments')

comment = file['comments'].first
expect(comment).to have_key('lineNumber')
expect(comment).to have_key('comment')

expect(question).not_to be_empty
expect(question).to have_key('title')
expect(question).to have_key('description')
end
end
end
end
end
8 changes: 8 additions & 0 deletions spec/factories/course_assessment_live_feedback_code.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true
FactoryBot.define do
factory :course_assessment_live_feedback_code, class: Course::Assessment::LiveFeedbackCode do
feedback { association(:course_assessment_live_feedback) }
filename { 'test_code.rb' }
content { 'puts "Hello, World!"' }
end
end
8 changes: 8 additions & 0 deletions spec/factories/course_assessment_live_feedback_comments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true
FactoryBot.define do
factory :course_assessment_live_feedback_comment, class: Course::Assessment::LiveFeedbackComment do
code { association(:course_assessment_live_feedback_code) }
line_number { 1 }
comment { 'This is a test comment' }
end
end
8 changes: 8 additions & 0 deletions spec/factories/course_assessment_live_feedbacks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true
FactoryBot.define do
factory :course_assessment_live_feedback, class: Course::Assessment::LiveFeedback do
assessment
question { association(:course_assessment_question_programming, assessment: assessment) }
creator { association(:course_user, course: assessment.course).user }
end
end

0 comments on commit c9eb16e

Please sign in to comment.