[Tests] Add basic tests for takedowns

Would have ccaught the breakage from frozen string literals
This commit is contained in:
Earlopain 2024-03-17 18:31:38 +01:00
parent 2609990837
commit 979e2e4d5f
No known key found for this signature in database
GPG Key ID: 48860312319ADF61
2 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,11 @@
# frozen_string_literal: true
FactoryBot.define do
factory(:takedown) do
creator_ip_addr { "127.0.0.1" }
email { "dummy@example.com" }
source { "example.com" }
reason { "foo" }
instructions { "bar" }
end
end

View File

@ -0,0 +1,29 @@
# frozen_string_literal: true
require "test_helper"
class TakedownsControllerTest < ActionDispatch::IntegrationTest
should "render the index" do
create_list(:takedown, 2)
get takedowns_path
assert_response :success
end
should "render the index for admins" do
create_list(:takedown, 2)
get_auth takedowns_path, create(:admin_user)
assert_response :success
end
should "allow creation" do
takedown_post = create(:post)
post takedowns_path, params: { takedown: { email: "dummy@example.com", reason: "foo", post_ids: "#{takedown_post.id} #{takedown_post.id + 1}" }, format: :json }
takedown = Takedown.last
assert_redirected_to takedown_path(takedown, code: takedown.vericode)
assert_equal(takedown_post.id.to_s, takedown.post_ids)
assert_operator(takedown.vericode.length, :>, 8)
end
end