2024-02-25 12:15:55 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "test_helper"
|
2017-02-06 17:06:23 -05:00
|
|
|
|
2018-04-02 13:51:26 -04:00
|
|
|
class IqdbQueriesControllerTest < ActionDispatch::IntegrationTest
|
2017-02-06 17:06:23 -05:00
|
|
|
context "The iqdb controller" do
|
|
|
|
setup do
|
2024-04-26 09:57:56 -04:00
|
|
|
IqdbProxy.stubs(:endpoint).returns("http://iqdb:5588")
|
2024-04-27 07:57:51 -04:00
|
|
|
CloudflareService.stubs(:ips).returns([])
|
2017-02-06 17:06:23 -05:00
|
|
|
end
|
|
|
|
|
2018-06-14 20:03:41 -04:00
|
|
|
context "show action" do
|
2018-06-23 13:32:39 -04:00
|
|
|
context "with a url parameter" do
|
|
|
|
should "render a response" do
|
2024-04-27 07:57:51 -04:00
|
|
|
post = create(:post)
|
|
|
|
create(:upload_whitelist, pattern: "https://google.com/*")
|
|
|
|
stub_request(:get, "https://google.com/foo.jpg")
|
|
|
|
.to_return(body: file_fixture("test.jpg").read)
|
|
|
|
response = [{ "post_id" => post.id, "score" => 80 }]
|
|
|
|
stub_request(:post, "#{IqdbProxy.endpoint}/query").to_return_json(body: response)
|
|
|
|
get iqdb_queries_path, params: { url: "https://google.com/foo.jpg" }
|
|
|
|
|
|
|
|
assert_response :success
|
|
|
|
assert_select("#post_#{post.id}")
|
2018-06-23 13:32:39 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a post_id parameter" do
|
2023-04-24 08:46:26 -04:00
|
|
|
should "redirect to iqdb" do
|
2024-04-27 07:57:51 -04:00
|
|
|
post = create(:post)
|
|
|
|
response = [{ "post_id" => post.id, "score" => 80 }]
|
|
|
|
stub_request(:post, "#{IqdbProxy.endpoint}/query").to_return_json(body: response)
|
|
|
|
Post.any_instance.stubs(:preview_file_path).returns(file_fixture("test.jpg"))
|
2018-06-23 13:32:39 -04:00
|
|
|
|
2024-04-27 07:57:51 -04:00
|
|
|
get iqdb_queries_path, params: { post_id: post.id }
|
2018-06-23 13:32:39 -04:00
|
|
|
assert_response :success
|
2024-04-27 07:57:51 -04:00
|
|
|
assert_select("#post_#{post.id}")
|
2022-05-26 16:49:43 -04:00
|
|
|
end
|
2017-04-05 19:48:57 -04:00
|
|
|
end
|
2017-02-06 17:06:23 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|