Return not_found Response If Video's Related Article is Not Found (#5169) [deploy]
This commit is contained in:
parent
00dd84f9e1
commit
4a2e55ff06
2 changed files with 16 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue