gracefully handle nil media_type

closes EVAL-4415
flag=speedgrader_studio_media_capture

Fixes a bug where the VideoCaptionService would raise an errror if the
media_type was nil. Now, it'll gracefully handle that case and set the
auto_caption_status on the media object to failed_initial_validation.

Test Plan:
- specs pass

Change-Id: Ie148c1ab43f87341bf761bd18658e1872d9dcb59
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/353784
Reviewed-by: Cameron Ray <cameron.ray@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
QA-Review: Spencer Olson <solson@instructure.com>
Product-Review: Cameron Ray <cameron.ray@instructure.com>
This commit is contained in:
Spencer Olson 2024-07-29 10:31:39 -05:00
parent 7dc2b9013a
commit 03845e3b41
2 changed files with 15 additions and 1 deletions

View File

@ -52,7 +52,7 @@ class VideoCaptionService < ApplicationService
def pass_initial_checks
return false unless config["app-host"].present?
return false unless auth_token.present?
return false unless @type.include?("video")
return false unless @type&.include?("video")
return false unless @media_id
return false if @media_object.media_tracks.where(kind: "subtitles").exists?
return false if url.nil?

View File

@ -21,6 +21,20 @@ RSpec.describe VideoCaptionService, type: :service do
let(:service) { VideoCaptionService.new(media_object, skip_polling: true) }
describe "#call" do
context "when media type is nil" do
it "handles the request gracefully and sets status to failed_initial_validation" do
media_object.update!(media_type: nil)
allow(service).to receive_messages(
config: { "app-host" => "https://example.com" },
auth_token: "token"
)
expect { service.call }.to change {
media_object.reload.auto_caption_status
}.from(nil).to("failed_initial_validation")
end
end
context "when media type is video and media id is present" do
before do
allow(service).to receive_messages(