Skip to content

Commit

Permalink
test(auto_source): add spec for routes
Browse files Browse the repository at this point in the history
  • Loading branch information
gildesmarais committed Oct 20, 2024
1 parent 7292678 commit e6b7016
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
20 changes: 10 additions & 10 deletions spec/fixtures/vcr_cassettes/auto_source-github-h2r-web.yml

Large diffs are not rendered by default.

22 changes: 15 additions & 7 deletions spec/routes/auto_source_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require 'spec_helper'

require 'rss'
require_relative '../../app'

describe Html2rss::Web::App do # rubocop:disable RSpec/SpecFilePathFormat
Expand All @@ -15,11 +15,21 @@ def app = described_class
let(:username) { 'username' }
let(:password) { 'password' }

let(:feed) do
RSS::Maker.make('2.0') do |maker|
maker.channel.title = 'title'
maker.channel.link = 'link'
maker.channel.description = 'description'
end
end

before do
allow(Html2rss::Web::AutoSource).to receive_messages(enabled?: true,
username:,
password:,
allowed_origins: Set['localhost'])

allow(Html2rss::Web::AutoSource).to receive(:build_auto_source_from_encoded_url).and_return(feed)
end

describe "GET '/auto_source/'" do
Expand Down Expand Up @@ -57,17 +67,15 @@ def app = described_class
describe "GET '/auto_source/:encoded_url'" do
context 'with provided basic auth' do
subject(:response) do
VCR.use_cassette('auto_source-github-h2r-web') do
get "/auto_source/#{Base64.urlsafe_encode64('https://github.com/html2rss/html2rss-web')}",
{},
request_headers.merge('HTTP_AUTHORIZATION' => basic_authorize(username, password))
end
get "/auto_source/#{Base64.urlsafe_encode64('https://github.com/html2rss/html2rss-web')}",
{},
request_headers.merge('HTTP_AUTHORIZATION' => basic_authorize(username, password))
end

it 'responds successfully', :aggregate_failures do
expect(response).to be_ok
expect(response.body).to start_with '<?xml version="1.0" encoding="UTF-8"?>'
expect(response.get_header('cache-control')).to eq 'must-revalidate, private, max-age=0'
expect(response.get_header('cache-control')).to eq 'must-revalidate, private, max-age=3600'
expect(response.get_header('content-type')).to eq described_class::CONTENT_TYPE_RSS
end
end
Expand Down

0 comments on commit e6b7016

Please sign in to comment.