Files
danbooru/test/functional/iqdb_queries_controller_test.rb
evazion 0f36bbf8d3 iqdb: update API client to use new version of IQDB.
Replace the old IQDB API client with a new client for the new forked
version of IQDB at https://github.com/danbooru/iqdb.

Changes:

* The /iqdb_queries endpoint now returns `hash` and `signature` fields.
  The `signature` is the full decoded Haar signature, while the `hash`
  is a encoded version of the signature.
* The /iqdb_queries endpoint no longer returns `width` and `height`
  fields in the response (these were always 128x128).
* We no longer need the IQDBs frontend server, now we talk to the IQDB
  instance directly.
* We no longer send add/remove image commands to IQDB through AWS SQS,
  now we send them to IQDB directly. They are sent in a delayed job so
  that if IQDB is down, uploading images is still possible, the add
  image commands will just get queued up.
* Fix a bug where regenerating an image's thumbnails didn't regenerate
  IQDB, because IQDB silently ignored add image commands when the image
  already existed in the database.
2021-06-16 05:36:24 -05:00

41 lines
1.1 KiB
Ruby

require 'test_helper'
class IqdbQueriesControllerTest < ActionDispatch::IntegrationTest
context "The iqdb controller" do
setup do
@user = create(:user)
@post = as(@user) { create(:post) }
end
context "show action" do
context "with a url parameter" do
should "render a response" do
@url = "https://google.com"
@matches = [{ post_id: @post.id, score: 95.0 }]
mock_iqdb_matches(@matches)
get_auth iqdb_queries_path, @user, as: :javascript, params: { url: @url }
assert_response :success
assert_select("#post_#{@post.id}")
end
end
context "with a post_id parameter" do
should "render a response" do
@matches = [{ post_id: @post.id, score: 95.0 }]
mock_iqdb_matches(@matches)
# Make the call to `@post.file(:preview)` work.
Post.any_instance.stubs(:file).returns(File.open("test/files/test.jpg"))
get_auth iqdb_queries_path, @user, params: { post_id: @post.id }
assert_response :success
assert_select("#post_#{@post.id}")
end
end
end
end
end