Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions test/controllers/medias_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ def setup
end

test "should be able to fetch HTML without token" do
get :index, params: { url: 'https://meedan.com/post/annual-report-2022', format: :html }
get :index, params: { url: 'https://meedan.org/post/annual-report-2022', format: :html }
assert_response :success
end

test "should ask to refresh cache" do
authenticate_with_token
get :index, params: { url: 'https://meedan.com/post/annual-report-2022', refresh: '1', format: :json }
get :index, params: { url: 'https://meedan.org/post/annual-report-2022', refresh: '1', format: :json }
first_parsed_at = Time.parse(JSON.parse(@response.body)['data']['parsed_at']).to_i
get :index, params: { url: 'https://meedan.com/post/annual-report-2022', format: :html }
name = Media.cache_key('https://meedan.com/post/annual-report-2022')
get :index, params: { url: 'https://meedan.org/post/annual-report-2022', format: :html }
name = Media.cache_key('https://meedan.org/post/annual-report-2022')
[:html, :json].each do |type|
assert Pender::Store.current.read(name, type), "#{name}.#{type} is missing"
end
sleep 1
get :index, params: { url: 'https://meedan.com/post/annual-report-2022', refresh: '1', format: :json }
get :index, params: { url: 'https://meedan.org/post/annual-report-2022', refresh: '1', format: :json }
assert !Pender::Store.current.read(name, :html), "#{name}.html should not exist"
second_parsed_at = Time.parse(JSON.parse(@response.body)['data']['parsed_at']).to_i
assert second_parsed_at > first_parsed_at
Expand All @@ -40,7 +40,7 @@ def setup

test "should ask to refresh cache with html format" do
authenticate_with_token
url = 'https://meedan.com/post/annual-report-2022'
url = 'https://meedan.org/post/annual-report-2022'
get :index, params: { url: url, refresh: '1', format: :html }
id = Media.cache_key(url)
first_parsed_at = Pender::Store.current.get(id, :html).last_modified
Expand All @@ -52,7 +52,7 @@ def setup

test "should not ask to refresh cache with html format" do
authenticate_with_token
url = 'https://meedan.com/post/annual-report-2022'
url = 'https://meedan.org/post/annual-report-2022'
id = Media.cache_key(url)
get :index, params: { url: url, refresh: '0', format: :html }
first_parsed_at = Pender::Store.current.get(id, :html).last_modified
Expand Down Expand Up @@ -175,11 +175,11 @@ def setup

test "should clear cache for multiple URLs sent as array" do
authenticate_with_token
url1 = 'https://meedan.com'
url2 = 'https://meedan.com/post/annual-report-2022'
url1 = 'https://meedan.org'
url2 = 'https://meedan.org/post/annual-report-2022'

normalized_url1 = 'https://meedan.com/'
normalized_url2 = 'https://meedan.com/post/annual-report-2022'
normalized_url1 = 'https://meedan.org/'
normalized_url2 = 'https://meedan.org/post/annual-report-2022'

id1 = Media.cache_key(normalized_url1)
id2 = Media.cache_key(normalized_url2)
Expand Down Expand Up @@ -301,7 +301,7 @@ def setup
WebMock.stub_request(:post, /example.com\/webhook/).to_return(status: 200, body: '')

authenticate_with_token(a)
url = 'https://meedan.com/post/annual-report-2022'
url = 'https://meedan.org/post/annual-report-2022'
get :index, params: { url: url, format: :json }
id = Media.cache_key(url)
assert_equal({}, Pender::Store.current.read(id, :json)[:archives].sort.to_h)
Expand All @@ -319,7 +319,7 @@ def setup
WebMock.stub_request(:post, /example.com\/webhook/).to_return(status: 200, body: '')

authenticate_with_token(a)
url = 'https://meedan.com/post/annual-report-2022'
url = 'https://meedan.org/post/annual-report-2022'
get :index, params: { url: url, archivers: 'none', format: :json }
id = Media.cache_key(url)
assert_equal({}, Pender::Store.current.read(id, :json)[:archives])
Expand All @@ -344,7 +344,7 @@ def setup
WebMock.stub_request(:post, /web.archive.org\/save/).to_return(body: {job_id: 'ebb13d31-7fcf-4dce-890c-c256e2823ca0' }.to_json)
WebMock.stub_request(:get, /web.archive.org\/save\/status/).to_return(body: {status: 'success', timestamp: 'timestamp'}.to_json)

url = 'https://meedan.com/post/annual-report-2022'
url = 'https://meedan.org/post/annual-report-2022'
archived = {"perma_cc"=>{"location"=>"http://perma.cc/perma-cc-guid-1"}, "archive_org"=>{"location"=>"https://web.archive.org/web/timestamp/#{url}"}}

authenticate_with_token(a)
Expand Down Expand Up @@ -393,8 +393,8 @@ def setup

test "should parse multiple URLs sent as list" do
authenticate_with_token
url1 = 'https://meedan.com/check'
url2 = 'https://meedan.com/about-us'
url1 = 'https://meedan.org/check'
url2 = 'https://meedan.org/about-us'
id1 = Media.cache_key(url1)
id2 = Media.cache_key(url2)
assert_nil Pender::Store.current.read(id1, :json)
Expand Down Expand Up @@ -508,7 +508,7 @@ def setup

test "should rescue and unlock url when raises error" do
authenticate_with_token
url = 'https://meedan.com/post/annual-report-2022'
url = 'https://meedan.org/post/annual-report-2022'
assert !Semaphore.new(url).locked?
[:js, :json, :html].each do |format|
@controller.stubs("render_as_#{format}".to_sym).raises(RuntimeError.new('error'))
Expand Down Expand Up @@ -595,7 +595,7 @@ def setup

test "should cache json and html on file" do
authenticate_with_token
url = 'https://meedan.com/post/annual-report-2022'
url = 'https://meedan.org/post/annual-report-2022'
id = Media.cache_key(url)
[:html, :json].each do |type|
assert !Pender::Store.current.read(id, type), "#{id}.#{type} should not exist"
Expand Down
2 changes: 1 addition & 1 deletion test/integration/parser/page_item_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class PageItemIntegrationTest < ActiveSupport::TestCase
assert_not_nil data['description']
assert_not_nil data['published_at']
assert_equal '', data['username']
assert_equal 'https://meedan.com', data['author_url']
assert_equal 'https://meedan.org', data['author_url']
assert_not_nil data['author_name']
assert_not_nil data['picture']
assert_nil data['error']
Expand Down
28 changes: 14 additions & 14 deletions test/models/media_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@ class MediaTest < ActiveSupport::TestCase

test "should normalize URL" do
variations = %w(
https://meedan.com
meedan.com
https://meedan.com:443
https://meedan.com//
https://meedan.com/?
https://meedan.com/#foo
https://meedan.com/
https://meedan.com
https://meedan.com/foo/..
https://meedan.com/?#
https://meedan.org
meedan.org
https://meedan.org:443
https://meedan.org//
https://meedan.org/?
https://meedan.org/#foo
https://meedan.org/
https://meedan.org
https://meedan.org/foo/..
https://meedan.org/?#
)
variations.each do |url|
media = Media.new(url: url)
assert_equal 'https://meedan.com/', media.url
assert_equal 'https://meedan.org/', media.url
end
end

test "should not normalize URL" do
urls = %w(
https://meedan.com/
https://example.com/
https://meedan.com/?foo=bar
https://meedan.org/
https://example.org/
https://meedan.org/?foo=bar
)
urls.each do |url|
media = Media.new(url: url)
Expand Down
Loading