Skip to content

Commit

Permalink
tests: add specs for duos
Browse files Browse the repository at this point in the history
  • Loading branch information
jeferson-sb committed Jan 6, 2024
1 parent 12e4772 commit 40580f9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/spec/factories/exams.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,11 @@
exam.questions = create_list(:question, evaluator.question_count, :with_options)
end
end

trait :with_duos do
after(:create) do |exam, evaluator|
exam.questions = create_list(:question, evaluator.question_count, :duos)
end
end
end
end
8 changes: 8 additions & 0 deletions api/spec/factories/questions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,13 @@
question.options.first.update(correct: true)
end
end

trait :duos do
after(:build) do |question, evaluator|
question.has_duo = true
question.options = build_list(:option, evaluator.options_count, question:)
question.options.first.update(correct: true)
end
end
end
end
35 changes: 35 additions & 0 deletions api/spec/requests/exams_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,39 @@
end
end
end

describe 'GET /exams/:id/duos' do
let!(:exam) { create(:exam, :with_duos, id: 1) }

describe 'when question.has_duo' do
it 'return duos list randomly' do
get '/api/exams/1/duos'

expect(response).to have_http_status(:success)

expect(json_body).to include('title')
expect(json_body['duos'][0].length).not_to eq(0)
expect(json_body['duos'][1].length).not_to eq(0)
end
end
end

describe 'POST /exams/:id/duos/evaluate' do
let!(:exam) { create(:exam, :with_duos, id: 1) }

describe 'when does not match duos' do
let(:params) do
{
duos: exam.questions.map { |q| [q.id, q.options[0].id] }
}
end

it 'return failure message' do
post('/api/exams/1/duos/evaluate', params:)

expect(response).to have_http_status(:success)
expect(json_body['message']).to eq('Oops, try again!')
end
end
end
end

0 comments on commit 40580f9

Please sign in to comment.