uploads: fix more tests.

This commit is contained in:
evazion
2022-01-29 22:53:04 -06:00
parent 810c3da939
commit 892c3899a8
6 changed files with 89 additions and 111 deletions

View File

@@ -343,93 +343,4 @@ class UploadServiceTest < ActiveSupport::TestCase
end
end
end
context "#create_post_from_upload" do
subject { UploadService }
setup do
CurrentUser.user = travel_to(1.month.ago) do
FactoryBot.create(:user)
end
CurrentUser.ip_addr = "127.0.0.1"
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "for a pixiv" do
setup do
@source = "https://i.pximg.net/img-original/img/2017/11/21/05/12/37/65981735_p0.jpg"
@ref = "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=65981735"
@upload = FactoryBot.create(:jpg_upload, file_size: 1000, md5: "12345", file_ext: "jpg", image_width: 100, image_height: 100, source: @source, referer_url: @ref)
end
should "record the canonical source" do
post = subject.new({}).create_post_from_upload(@upload)
assert_equal(@source, post.source)
end
end
context "for a twitter" do
setup do
@source = "https://pbs.twimg.com/media/C1kt72yVEAEGpOv.jpg:large"
@ref = "https://twitter.com/aranobu/status/817736083567820800"
@upload = FactoryBot.create(:jpg_upload, file_size: 1000, md5: "12345", file_ext: "jpg", image_width: 100, image_height: 100, source: @source, referer_url: @ref)
end
should "record the canonical source" do
post = subject.new({}).create_post_from_upload(@upload)
assert_equal(@ref, post.source)
end
end
context "for nijie" do
should "record the canonical source" do
page_url = "https://nijie.info/view.php?id=728995"
image_url = "https://pic03.nijie.info/nijie_picture/728995_20170505014820_0.jpg"
upload = FactoryBot.create(:jpg_upload, file_size: 1000, md5: "12345", file_ext: "jpg", image_width: 100, image_height: 100, source: image_url, referer_url: page_url)
post = UploadService.new({}).create_post_from_upload(upload)
assert_equal(page_url, post.source)
end
end
context "for an image" do
setup do
@upload = FactoryBot.create(:source_upload, file_size: 1000, md5: "12345", file_ext: "jpg", image_width: 100, image_height: 100)
end
should "create a commentary record if the commentary is present" do
assert_difference("ArtistCommentary.count", 1) do
@upload.update!(
artist_commentary_title: "blah",
artist_commentary_desc: "blah",
translated_commentary_title: "blah",
translated_commentary_desc: "blah"
)
UploadService.new({}).create_post_from_upload(@upload)
end
end
should "not create a commentary record if the commentary is blank" do
assert_difference("ArtistCommentary.count", 0) do
@upload.update!(
artist_commentary_title: "",
artist_commentary_desc: "",
translated_commentary_title: "",
translated_commentary_desc: ""
)
UploadService.new({}).create_post_from_upload(@upload)
end
end
should "create a post" do
post = subject.new({}).create_post_from_upload(@upload)
assert_equal([], post.errors.full_messages)
assert_not_nil(post.id)
end
end
end
end