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 48cc618 commit c955924
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
14 changes: 14 additions & 0 deletions spec/html2rss/web/helpers/auto_source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,18 @@
end
end
# rubocop:enable RSpec/NamedSubject, RSpec/MessageSpies

describe '.build_auto_source_from_encoded_url' do
subject(:feed) do
VCR.use_cassette('auto_source-github-h2r-web', match_requests_on: [:host]) do
described_class.build_auto_source_from_encoded_url(encoded_url)
end
end

let(:encoded_url) { Base64.urlsafe_encode64('https://github.com/html2rss/html2rss-web') }

it 'returns an RSS::Rss object' do
expect(feed).to be_a(RSS::Rss)
end
end
end
22 changes: 16 additions & 6 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 Down Expand Up @@ -57,17 +57,27 @@ 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))
get "/auto_source/#{Base64.urlsafe_encode64('https://github.com/html2rss/html2rss-web')}",
{},
request_headers.merge('HTTP_AUTHORIZATION' => basic_authorize(username, password))
end

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(:build_auto_source_from_encoded_url).and_return(feed)
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 c955924

Please sign in to comment.