docbrown/spec/requests/video_states_update_spec.rb
Anna Buianova 7d053471f8
Rubocop fixes in spec/requests (#18946)
* Rubocop fixes in spec/requests

* Fixed spec/requests/api/v0/articles_spec.rb

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>
2023-01-12 19:10:16 +03:00

33 lines
1.1 KiB
Ruby

require "rails_helper"
RSpec.describe "VideoStatesUpdate" do
let(:encoder_key) { "TEST_SECRET" }
let(:article) { create(:article, video_code: "DUMMY_VID_CODE") }
before do
allow(Settings::General).to receive(:video_encoder_key).and_return(encoder_key)
end
describe "POST /video_states" do
it "updates video state" do
input = JSON.unparse(input: { key: article.video_code })
post "/video_states?key=#{encoder_key}",
params: { Message: input }.to_json
expect(Article.last.video_state).to eq("COMPLETED")
end
it "rejects invalid key" do
post "/video_states?key=not_a_valid_key",
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=#{encoder_key}",
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