mirror of
https://github.com/neocities/neocities.git
synced 2025-08-04 00:31:59 +02:00
fixes for screenshot worker
This commit is contained in:
parent
0aca6b3328
commit
fbf78f04d6
8 changed files with 69 additions and 2 deletions
|
@ -17,6 +17,9 @@ Bundler.require :test
|
|||
|
||||
#require 'minitest/pride'
|
||||
require 'minitest/autorun'
|
||||
require 'webmock'
|
||||
include WebMock::API
|
||||
require 'webmock/minitest'
|
||||
require 'sidekiq/testing'
|
||||
|
||||
Sinatra::Application.configure do |app|
|
||||
|
|
8
tests/files/index.html
Normal file
8
tests/files/index.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Hello?</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hi there!</h1>
|
||||
</body>
|
||||
</html>
|
|
@ -9,6 +9,24 @@ end
|
|||
|
||||
describe 'site_files' do
|
||||
describe 'upload' do
|
||||
|
||||
it 'succeeds with index.html file' do
|
||||
site = Fabricate :site
|
||||
PurgeCacheWorker.jobs.clear
|
||||
ScreenshotWorker.jobs.clear
|
||||
|
||||
post '/site_files/upload', {
|
||||
'files[]' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'text/html'),
|
||||
'csrf_token' => 'abcd'
|
||||
}, {'rack.session' => { 'id' => site.id, '_csrf_token' => 'abcd' }}
|
||||
last_response.body.must_match /successfully uploaded/i
|
||||
File.exists?(site.files_path('index.html')).must_equal true
|
||||
|
||||
args = ScreenshotWorker.jobs.first['args']
|
||||
args.first.must_equal site.username
|
||||
args.last.must_equal 'index.html'
|
||||
end
|
||||
|
||||
it 'succeeds with valid file' do
|
||||
site = Fabricate :site
|
||||
PurgeCacheWorker.jobs.clear
|
||||
|
|
28
tests/workers/screenshot_worker_tests.rb
Normal file
28
tests/workers/screenshot_worker_tests.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
require_relative '../environment.rb'
|
||||
|
||||
describe ScreenshotWorker do
|
||||
|
||||
it 'saves a screenshot for a root html file' do
|
||||
worker = ScreenshotWorker.new
|
||||
worker.perform 'kyledrake', 'index.html'
|
||||
site = Fabricate :site
|
||||
Site::SCREENSHOT_RESOLUTIONS.each do |r|
|
||||
File.exists?(File.join(Site::SCREENSHOTS_ROOT, 'kyledrake', "index.html.#{r}.jpg")).must_equal true
|
||||
site.screenshot_url('index.html', r).must_equal(
|
||||
File.join(Site::SCREENSHOTS_URL_ROOT, site.username, "index.html.#{r}.jpg")
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
it 'saves a screenshot for a path html file' do
|
||||
worker = ScreenshotWorker.new
|
||||
worker.perform 'kyledrake', 'derpie/derp/index.html'
|
||||
site = Fabricate :site
|
||||
Site::SCREENSHOT_RESOLUTIONS.each do |r|
|
||||
File.exists?(File.join(Site::SCREENSHOTS_ROOT, 'kyledrake', "derpie/derp/index.html.#{r}.jpg")).must_equal true
|
||||
site.screenshot_url('derpie/derp/index.html', r).must_equal(
|
||||
File.join(Site::SCREENSHOTS_URL_ROOT, site.username, "derpie/derp/index.html.#{r}.jpg")
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue