1
- # require 'swagger_helper'
2
- # require 'json_web_token'
3
-
4
- # RSpec.describe 'StudentQuizzesController', type: :request do
5
- # before(:all) do
6
- # @roles = create_roles_hierarchy
7
- # end
8
-
9
- # let(:instructor) {
10
- # User.create(
11
- # name: "insta",
12
- # password_digest: "password",
13
- # role_id: @roles[:instructor].id,
14
- # full_name: "Instructor A",
15
-
16
- # mru_directory_path: "/home/testuser"
17
- # )
18
- # }
19
-
20
- # let(:student) {
21
- # User.create(
22
- # name: "stud",
23
- # password_digest: "password",
24
- # role_id: @roles[:student].id,
25
- # full_name: "Student Student",
26
-
27
- # mru_directory_path: "/home/testuser"
28
- # )
29
- # }
30
-
31
- # # Embed token based authentication for tests
32
- # let(:token) { JsonWebToken.encode({ id: instructor.id }) }
33
- # let(:auth_headers) { { "Authorization" => "Bearer #{token}", "Content-Type" => "application/json" } }
34
-
35
- # before do
36
- # allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(instructor)
37
- # allow_any_instance_of(Api::V1::StudentQuizzesController).to receive(:check_instructor_role).and_return(true)
38
- # end
39
-
40
- # describe '#index' do
41
- # it "returns a list of quizzes" do
42
- # # Create a sample quiz first.
43
- # Questionnaire.create!(name: "Quiz One", instructor_id: instructor.id,
44
- # min_question_score: 0, max_question_score: 10)
45
- # get '/api/v1/student_quizzes', headers: auth_headers
46
- # expect(response).to have_http_status(:ok)
47
- # quizzes = JSON.parse(response.body)
48
- # expect(quizzes).to be_an(Array)
49
- # end
50
- # end
51
-
52
- # describe '#create' do
53
- # let(:assignment) { Assignment.create!(name: "Test Assignment", instructor_id: instructor.id) }
54
- # let(:quiz_params) do
55
- # {
56
- # questionnaire: {
57
- # name: 'New Quiz',
58
- # instructor_id: instructor.id,
59
- # min_question_score: 1,
60
- # max_question_score: 5,
61
- # assignment_id: assignment.id,
62
- # questionnaire_type: "Quiz", # added required field
63
- # private: false, # added required field
64
- # questions_attributes: [
65
- # {
66
- # seq: 1,
67
- # txt: 'What is Ruby?',
68
- # question_type: 'MultipleChoiceCheckbox',
69
- # break_before: false,
70
- # score_value: 1,
71
- # correct_answer: nil,
72
- # answers_attributes: [
73
- # {
74
- # answer_text: 'A gemstone',
75
- # correct: false
76
- # },
77
- # {
78
- # answer_text: 'A programming language',
79
- # correct: true
80
- # }
81
- # ]
82
- # }
83
- # ]
84
- # }
85
- # }
86
- # end
87
-
88
- # it "creates a new quiz with questions and answers" do
89
- # post '/api/v1/student_quizzes', params: quiz_params.to_json, headers: auth_headers
90
- # expect(response).to have_http_status(:created)
91
- # data = JSON.parse(response.body)
92
- # expect(data["name"]).to eq("New Quiz")
93
- # expect(data).to have_key("questions")
94
- # end
95
- # end
96
-
97
- # describe '#destroy' do
98
- # it "destroys an existing quiz" do
99
- # quiz = Questionnaire.create!(name: "Quiz To Delete", instructor_id: instructor.id,
100
- # min_question_score: 0, max_question_score: 10)
101
- # delete "/api/v1/student_quizzes/#{quiz.id}", headers: auth_headers
102
- # expect(response).to have_http_status(:no_content)
103
- # expect { Questionnaire.find(quiz.id) }.to raise_error(ActiveRecord::RecordNotFound)
104
- # end
105
- # end
106
-
107
- # describe '#show' do
108
- # it "shows an existing quiz" do
109
- # quiz = Questionnaire.create!(name: "Quiz Show", instructor_id: instructor.id,
110
- # min_question_score: 0, max_question_score: 10)
111
- # get "/api/v1/student_quizzes/#{quiz.id}", headers: auth_headers
112
- # expect(response).to have_http_status(:ok)
113
- # data = JSON.parse(response.body)
114
- # expect(data["id"]).to eq(quiz.id)
115
- # expect(data["name"]).to eq("Quiz Show")
116
- # end
117
- # end
118
-
119
- # let(:dummy_assignment) { Assignment.create!(name: "Dummy Assignment") }
120
-
121
- # describe '#assign_quiz' do
122
- # let(:dummy_assignment) { Assignment.create!(name: "Dummy Assignment", instructor_id: instructor.id) }
123
- # it "assigns a quiz to a participant" do
124
- # participant = Participant.create!(user_id: student.id, assignment_id: dummy_assignment.id)
125
- # quiz = Questionnaire.create!(name: "Quiz To Assign", instructor_id: instructor.id,
126
- # min_question_score: 0, max_question_score: 10)
127
- # params = { participant_id: participant.id, questionnaire_id: quiz.id }
128
- # post "/api/v1/student_quizzes/assign", params: params.to_json, headers: auth_headers
129
- # expect(response).to have_http_status(:created)
130
- # end
131
- # end
132
-
133
- # describe '#submit_quiz' do
134
- # it "submits quiz answers and returns total score" do
135
- # # Create a quiz and a response map for the current student.
136
- # quiz = Questionnaire.create!(name: "Quiz Submit", instructor_id: instructor.id,
137
- # min_question_score: 0, max_question_score: 10)
138
- # response_map = ResponseMap.create!(reviewee_id: student.id,
139
- # reviewer_id: quiz.instructor_id,
140
- # reviewed_object_id: quiz.id, score: 0)
141
- # submission_params = {
142
- # questionnaire_id: quiz.id,
143
- # answers: [ { question_id: 1, answer: 1 } ]
144
- # }
145
- # post "/api/v1/student_quizzes/submit_answers", params: submission_params.to_json, headers: auth_headers
146
- # expect(response).to have_http_status(:ok)
147
- # data = JSON.parse(response.body)
148
- # expect(data).to have_key("total_score")
149
- # end
150
- # end
151
-
152
- # describe '#update' do
153
- # it "updates the quiz successfully" do
154
- # quiz = Questionnaire.create!(name: "Old Quiz Name", instructor_id: instructor.id,
155
- # min_question_score: 0, max_question_score: 10)
156
- # update_params = { questionnaire: { name: "Updated Quiz Name" } }
157
- # put "/api/v1/student_quizzes/#{quiz.id}", params: update_params.to_json, headers: auth_headers
158
- # expect(response).to have_http_status(:ok)
159
- # data = JSON.parse(response.body)
160
- # expect(data["name"]).to eq("Updated Quiz Name")
161
- # end
162
- # end
163
-
164
- # describe '#fetch_quiz' do
165
- # it "retrieves a quiz using the fetch_quiz logic" do
166
- # quiz = Questionnaire.create!(name: "Fetch Quiz", instructor_id: instructor.id,
167
- # min_question_score: 0, max_question_score: 10)
168
- # get "/api/v1/student_quizzes/#{quiz.id}", headers: auth_headers
169
- # expect(response).to have_http_status(:ok)
170
- # data = JSON.parse(response.body)
171
- # expect(data["name"]).to eq("Fetch Quiz")
172
- # end
173
- # end
174
-
175
- # describe '#render_success' do
176
- # it "renders a success response when invoked via an action" do
177
- # # Using the index action, which calls render_success.
178
- # get "/api/v1/student_quizzes", headers: auth_headers
179
- # expect(response).to have_http_status(:ok)
180
- # end
181
- # end
182
- # end
0 commit comments