Skip to content

Conversation

@jamiebenstead
Copy link
Contributor

Status

What's changed?

  • Added read_at datetime to the feedback table
  • Created endpoint to set feedback as read
  • Added functionality to set a datetime on the read_at field on feedback
  • Added tests

response
rescue StandardError => e
Sentry.capture_exception(e)
response[:error] = response[:feedback]&.errors
response
rescue StandardError => e
Sentry.capture_exception(e)
response[:error] = response[:feedback]&.errors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This follows existing patterns, so I think it's fine

Comment on lines +15 to +18
it 'returns the updated feedback' do
response = described_class.call(feedback: feedback)
expect(response[:feedback]).to eq(feedback)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused what this is testing to be honest. Might be simpler to test it is an instance of Feedback and then check the read at was set below like you're already doing


context 'when set_read fails' do
before do
allow(feedback).to receive(:save!).and_raise(StandardError, 'Transition failed')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nitpicky sorry, but there might be a better example of an error message, just because Transition failed is quite specific to the state machine stuff

Comment on lines +41 to +44
it 'returns the original feedback' do
response = described_class.call(feedback: feedback)
expect(response[:feedback]).to eq(feedback)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the same test as the one you have above, where response[:feedback] should have changed, so I'm confused

Comment on lines +52 to +54
it 'includes an error object in the response' do
response = described_class.call(feedback: feedback)
expect(response[:error]).to be_a(ActiveModel::Errors)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be good to test it returns the error you set above

Comment on lines +33 to +43
def set_read
feedback = Feedback.find(params[:id])
result = Feedback::SetRead.call(feedback: feedback)

if result.success?
@feedback = result[:feedback]
render :show, formats: [:json], status: :ok
else
render json: { error: result[:error] }, status: :unprocessable_entity
end
end
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants