diff --git a/app/controllers/video_states_controller.rb b/app/controllers/video_states_controller.rb index 97639ff56..4bdf91c1a 100644 --- a/app/controllers/video_states_controller.rb +++ b/app/controllers/video_states_controller.rb @@ -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 diff --git a/spec/requests/video_states_update_spec.rb b/spec/requests/video_states_update_spec.rb index 9c1ebf966..2a1185f0e 100644 --- a/spec/requests/video_states_update_spec.rb +++ b/spec/requests/video_states_update_spec.rb @@ -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