-
Notifications
You must be signed in to change notification settings - Fork 5
Index route for feedback #604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+150
−4
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
93d9b21
initial index route for feedback
loiswells97 eca8c34
fixing rubocop
loiswells97 beba6d4
testing and adding error states to feedback index route
loiswells97 90f741c
ability spec
loiswells97 e74170e
Merge branch 'main' into index-feedback
loiswells97 b63a81a
refactoring feedback controller to make it more DRY
loiswells97 ba7c16e
Add comment to explain explicit feedback authorisation
loiswells97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| json.array!(@feedback) do |feedback| | ||
| json.partial! 'feedback', feedback: | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe 'List feedback requests', type: :request do | ||
| let(:headers) { { Authorization: UserProfileMock::TOKEN } } | ||
| let(:school) { create(:school) } | ||
| let(:student) { create(:student, school:) } | ||
| let(:teacher) { create(:teacher, school:) } | ||
| let(:school_class) { create(:school_class, teacher_ids: [teacher.id], school:) } | ||
| let(:class_student) { create(:class_student, school_class:, student_id: student.id) } | ||
| let(:lesson) { create(:lesson, school:, school_class:, user_id: teacher.id, visibility: 'students') } | ||
| let(:teacher_project) { create(:project, user_id: teacher.id, school:, lesson:) } | ||
| let(:student_project) { create(:project, user_id: class_student.student_id, school:, parent: teacher_project) } | ||
| let!(:feedback) { create(:feedback, school_project: student_project.school_project, user_id: teacher.id, content: 'Excellent work!') } | ||
|
|
||
| context 'when logged in as the class teacher' do | ||
| before do | ||
| authenticated_in_hydra_as(teacher) | ||
| end | ||
|
|
||
| context 'when listing feedback for student work' do | ||
| before do | ||
| get("/api/projects/#{student_project.identifier}/feedback", headers:) | ||
| end | ||
|
|
||
| it 'returns ok response' do | ||
| expect(response).to have_http_status(:ok) | ||
| end | ||
|
|
||
| it 'returns a list of the feedback' do | ||
| data = JSON.parse(response.body, symbolize_names: true) | ||
| expect(data.count).to eq(1) | ||
| end | ||
|
|
||
| it 'returns the feedback json containing feedback content' do | ||
| data = JSON.parse(response.body, symbolize_names: true) | ||
| expect(data[0][:content]).to eq(feedback.content) | ||
| end | ||
| end | ||
|
|
||
| context 'when listing feedback for a project that is not student work' do | ||
| before do | ||
| get("/api/projects/#{teacher_project.identifier}/feedback", headers:) | ||
| end | ||
|
|
||
| it 'returns ok response' do | ||
| expect(response).to have_http_status(:ok) | ||
| end | ||
|
|
||
| it 'returns an empty list' do | ||
| data = JSON.parse(response.body, symbolize_names: true) | ||
| expect(data).to be_empty | ||
| end | ||
| end | ||
|
|
||
| context 'when the project does not exist' do | ||
| before do | ||
| get('/api/projects/does-not-exist/feedback', headers:) | ||
| end | ||
|
|
||
| it 'returns not found response' do | ||
| expect(response).to have_http_status(:not_found) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context 'when logged in as another teacher' do | ||
| let(:other_teacher) { create(:teacher, school:) } | ||
|
|
||
| before do | ||
| authenticated_in_hydra_as(other_teacher) | ||
| get("/api/projects/#{student_project.identifier}/feedback", headers:) | ||
| end | ||
|
|
||
| it 'returns forbidden response' do | ||
| expect(response).to have_http_status(:forbidden) | ||
| end | ||
| end | ||
|
|
||
| context 'when logged in as the student' do | ||
| before do | ||
| authenticated_in_hydra_as(student) | ||
| get("/api/projects/#{student_project.identifier}/feedback", headers:) | ||
| end | ||
|
|
||
| it 'returns ok response' do | ||
| expect(response).to have_http_status(:ok) | ||
| end | ||
|
|
||
| it 'returns the feedback json containing feedback content' do | ||
| data = JSON.parse(response.body, symbolize_names: true) | ||
| expect(data[0][:content]).to eq(feedback.content) | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.