-
Notifications
You must be signed in to change notification settings - Fork 5
Add ability to set read at on feedback #610
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
Open
jamiebenstead
wants to merge
8
commits into
main
Choose a base branch
from
add-ability-to-set-read_at-on-feedback
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+190
−6
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3218e96
Create migration
jamiebenstead d50910e
Run migration to add read_at to feedback
jamiebenstead 25114a3
Create read endpoint, add functionality
jamiebenstead 3b059e9
Add api route tests
jamiebenstead 74e82eb
Add test file for set_read
jamiebenstead 27bd784
Add tests around when set_read fails
jamiebenstead 27a1438
Add set_read tests to ability_spec
jamiebenstead 1c1b177
Update error response and tests
jamiebenstead 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
Some comments aren't visible on the classic Files Changed page.
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 |
|---|---|---|
|
|
@@ -7,5 +7,6 @@ json.call( | |
| :user_id, | ||
| :content, | ||
| :created_at, | ||
| :updated_at | ||
| :updated_at, | ||
| :read_at | ||
| ) | ||
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 @@ | ||
| class AddReadAtToFeedback < ActiveRecord::Migration[7.2] | ||
| def change | ||
| add_column :feedback, :read_at, :datetime | ||
| end | ||
| end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,19 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class Feedback | ||
| class SetRead | ||
| class << self | ||
| def call(feedback:) | ||
| response = OperationResponse.new | ||
| response[:feedback] = feedback | ||
| response[:feedback].read_at = Time.current | ||
| response[:feedback].save! | ||
| response | ||
| rescue StandardError => e | ||
| Sentry.capture_exception(e) | ||
| response[:error] = e.message | ||
| response | ||
| end | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe Feedback::SetRead, type: :unit do | ||
| let(:feedback) { create(:feedback) } | ||
|
|
||
| describe '.call' do | ||
| context 'when set_read is successful' do | ||
| it 'returns a successful operation response' do | ||
| response = described_class.call(feedback: feedback) | ||
| expect(response.success?).to be(true) | ||
| end | ||
|
|
||
| it 'returns the updated feedback' do | ||
| response = described_class.call(feedback: feedback) | ||
| expect(response[:feedback]).to be_a(Feedback) | ||
| end | ||
|
|
||
| it 'returns read_at' do | ||
| response = described_class.call(feedback: feedback) | ||
| expect(response[:feedback].read_at).to be_present | ||
| end | ||
|
|
||
| it 'returns read_at as a timestamp' do | ||
| response = described_class.call(feedback: feedback) | ||
| expect(response[:feedback].read_at).to be_a(ActiveSupport::TimeWithZone) | ||
| end | ||
| end | ||
|
|
||
| context 'when set_read fails' do | ||
| before do | ||
| allow(feedback).to receive(:save!).and_raise(StandardError, 'Some API error') | ||
| end | ||
|
|
||
| it 'returns a failed operation response' do | ||
| response = described_class.call(feedback: feedback) | ||
| expect(response.success?).to be(false) | ||
| end | ||
|
|
||
| it 'does not persist read_at' do | ||
| described_class.call(feedback: feedback) | ||
| feedback.reload | ||
| expect(feedback.read_at).to be_nil | ||
| end | ||
|
|
||
| it 'includes the correct error response' do | ||
| response = described_class.call(feedback: feedback) | ||
| expect(response[:error]).to eq('Some API error') | ||
| end | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe 'Set read_at on 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!') } | ||
| let(:feedback_json) do | ||
| { | ||
| id: feedback.id, | ||
| school_project_id: feedback.school_project_id, | ||
| user_id: feedback.user_id, | ||
| content: feedback.content, | ||
| created_at: feedback.created_at, | ||
| updated_at: feedback.updated_at, | ||
| read_at: feedback.read_at | ||
| }.to_json | ||
| end | ||
|
|
||
| context 'when logged in as the class teacher' do | ||
| before do | ||
| authenticated_in_hydra_as(teacher) | ||
| put("/api/projects/#{student_project.identifier}/feedback/#{feedback.id}/read", headers: headers) | ||
| feedback.reload | ||
| end | ||
|
|
||
| it 'returns forbidden response' do | ||
| expect(response).to have_http_status(:forbidden) | ||
| end | ||
|
|
||
| it 'does not set the read_at on feedback' do | ||
| expect(feedback.read_at).to be_nil | ||
| end | ||
| end | ||
|
|
||
| context 'when logged in as the student' do | ||
| before do | ||
| authenticated_in_hydra_as(student) | ||
| end | ||
|
|
||
| context 'when feedback exists' do | ||
| before do | ||
| put("/api/projects/#{student_project.identifier}/feedback/#{feedback.id}/read", headers: headers) | ||
| feedback.reload | ||
| end | ||
|
|
||
| it 'returns ok response' do | ||
| expect(response).to have_http_status(:ok) | ||
| end | ||
|
|
||
| it 'returns the feedback json' do | ||
| expect(response.body).to eq(feedback_json) | ||
| end | ||
|
|
||
| it 'does set the read_at on feedback' do | ||
| expect(feedback.read_at).to be_present | ||
| end | ||
|
|
||
| it 'sets read_at to be a time' do | ||
| expect(feedback.read_at).to be_a(ActiveSupport::TimeWithZone) | ||
| end | ||
|
|
||
| it 'sets read_at to a recent time' do | ||
| expect(feedback.read_at).to be_within(5.seconds).of(Time.current) | ||
| end | ||
| end | ||
|
|
||
| context 'when feedback does not exist' do | ||
| before do | ||
| put("/api/projects/#{student_project.identifier}/feedback/does-not-exist/read", headers: headers) | ||
| feedback.reload | ||
| end | ||
|
|
||
| it 'returns not found response' do | ||
| expect(response).to have_http_status(:not_found) | ||
| end | ||
| 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want to 404 it if the feedback id is invalid?