Return not_found Response If Video's Related Article is Not Found (#5169) [deploy]

This commit is contained in:
Molly Struve 2019-12-19 09:41:59 -06:00 committed by GitHub
parent 00dd84f9e1
commit 4a2e55ff06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View file

@ -18,9 +18,14 @@ class VideoStatesController < ApplicationController
request_json = JSON.parse(request.raw_post, symbolize_names: true)
message_json = JSON.parse(request_json[:Message], symbolize_names: true)
@article = Article.find_by(video_code: message_json[:input][:key])
@article.update(video_state: "COMPLETED") # Only is called on completion
NotifyMailer.video_upload_complete_email(@article).deliver
render json: { message: "Video state updated" }
if @article
@article.update(video_state: "COMPLETED") # Only is called on completion
NotifyMailer.video_upload_complete_email(@article).deliver
render json: { message: "Video state updated" }
else
render json: { message: "Related article not found" }, status: :not_found
end
end
def valid_user

View file

@ -19,5 +19,13 @@ RSpec.describe "VideoStatesUpdate", type: :request do
params: { input: { key: article.video_code } }
expect(response).to have_http_status(:unprocessable_entity)
end
it "returns not_found if video article is not found" do
input = JSON.unparse(input: { key: "abc" })
post "/video_states?key=#{authorized_user.secret}",
params: { Message: input }.to_json
expect(response).to have_http_status(:not_found)
expect(response.parsed_body["message"]).to eq("Related article not found")
end
end
end