New API method: /api/list

This commit is contained in:
Kyle Drake 2016-02-12 19:07:24 -08:00
parent 6ba8efaa11
commit bbe57750da
3 changed files with 119 additions and 1 deletions

View file

@ -14,6 +14,46 @@ def create_site(opts={})
@pass = site_attr[:password]
end
describe 'api list' do
it 'returns all files without path' do
create_site
basic_authorize @user, @pass
get '/api/list'
res[:result].must_equal 'success'
res[:files].length.must_equal @site.site_files.length
res[:files].each do |file|
site_file = @site.site_files.select {|s| s[:path] == file[:path]}.first
site_file[:is_directory].must_equal file[:is_directory]
site_file[:size].must_equal file[:size]
site_file[:updated_at].rfc2822.must_equal file[:updated_at]
end
end
it 'shows empty array for missing path' do
create_site
basic_authorize @user, @pass
get '/api/list', path: '/fail'
res[:result].must_equal 'success'
res[:files].must_equal []
end
it 'shows files in path' do
create_site
tempfile = Tempfile.new
tempfile.write('meep html')
@site.store_files [{filename: '/derp/test.html', tempfile: tempfile}]
basic_authorize @user, @pass
get '/api/list', path: '/derp'
res[:result].must_equal 'success'
res[:files].length.must_equal 1
file = res[:files].first
file[:path].must_equal 'derp/test.html'
file[:updated_at].must_equal @site.site_files.select {|s| s.path == 'derp/test.html'}.first.updated_at.rfc2822
end
end
describe 'api info' do
it 'fails for no input' do
get '/api/info'